0

I have the following code in order to remove ALL invalid Unicode characters before sending them in XML in a SOAP request.

const invalidUnicodeRemoved = inputText.replace(/[\u0000-\u001F]/gm, '');

However, I keep getting the following error sending the XML: An invalid XML character (Unicode: 0x1) was found in the element content of the document.. So basically it has not been removed (or at least not all of them).

Any ideas?

  • Possible duplicate of https://stackoverflow.com/questions/280712/javascript-unicode-regexes – randomir Jul 10 '17 at 10:13
  • @randomir I don't understand why it is a duplicate from that question. Seems to be a different issue. –  Jul 10 '17 at 10:17
  • See [the answer](https://stackoverflow.com/a/280762/404556). JavaScript has a problem with unicode ranges. Btw, are you running this in node.js or browser? – randomir Jul 10 '17 at 10:20
  • If it's in node.js (ES6), the solution is to use `u` modifier in regex. – randomir Jul 10 '17 at 10:21
  • In node.js. Seems that the issue with ranges was before ES6, right? I believe I am implementing it the way they recommend for ES6. –  Jul 10 '17 at 10:22
  • 1
    Have you tried adding `u` modifier, like this: `/[\u0000-\u001F]/gmu`? – randomir Jul 10 '17 at 10:23

0 Answers0