padolsey / findAndReplaceDOMText

:mag: Find and replace DOM text
777 stars 146 forks source link

Empty values in optional capture groups are rendered as undefined #70

Closed ardcore closed 6 years ago

ardcore commented 6 years ago

When using replace with optional capture groups findAndReplaceDOMText seems to replace empty capture group values with undefined in HTML (instead of empty string). Example:

findAndReplaceDOMText(context, {
  find: /(This)(\s+)?(document),
  replace: "$1$2$3",
});

ran against Thisdocument (in HTML) will result in Thisundefineddocument

padolsey commented 6 years ago

Hmm, am having a hard time reproducing: https://jsfiddle.net/fdqcsy9p/

Could you post the specific code that breaks if possible? Or create a small failing test case / fiddle?

ardcore commented 6 years ago

https://jsfiddle.net/ef5z8j0g/ (same code, just fixed errors in your fiddle coming from my lousy paste :))

padolsey commented 6 years ago

Should be fixed in v0.4.6.

padolsey commented 6 years ago

(Thanks for reporting this! And lemme know if you find any other weird bugs.)

ardcore commented 6 years ago

Thanks for the quick turnaround!