Skip to content

Commit

Permalink
Merge pull request #161 from Dashlane/es5-compatible-unicode-regexp
Browse files Browse the repository at this point in the history
Use an ES5 compatible Regexp to assert legal characters. Closes #147.
  • Loading branch information
oozcitak committed Jun 6, 2017
2 parents 3b6d2d7 + ca42e68 commit 7b96de9
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
2 changes: 2 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
language: node_js
node_js:
- "4.0"
- "5.0"
- "6.0"
- "node"
after_success:
Expand Down
4 changes: 3 additions & 1 deletion src/XMLStringifier.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,9 @@ module.exports = class XMLStringifier
# Valid characters from https://www.w3.org/TR/xml11/#charsets
# any Unicode character, excluding the surrogate blocks, FFFE, and FFFF.
# [#x1-#xD7FF] | [#xE000-#xFFFD] | [#x10000-#x10FFFF]
res = str.match /[\u{0000}\u{D800}-\u{DFFF}\u{FFFE}-\u{FFFF}]/u
# This complex ES5 compatible Regexp has been generated using the "regenerate" NPM module
# `regenerate().add(0x0000).addRange(0xD800, 0xDFFF).addRange(0xFFFE, 0xFFFF).toString()`
res = str.match /[\0\uFFFE\uFFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF]/
if res
throw new Error "Invalid character in string: #{str} at index #{res.index}"

Expand Down

0 comments on commit 7b96de9

Please sign in to comment.