Skip to content

Commit

Permalink
Fix invalid regex for U+10000-U+10FFFF range
Browse files Browse the repository at this point in the history
This fixes a bad unicode range in the INVALID_XML10_CHARS regex which
caused valid XML unicode character to be escaped.
  • Loading branch information
felixbuenemann committed Oct 30, 2017
1 parent 763904c commit 229ab50
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/xlsxtream/xml.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ module XML

# http://www.w3.org/TR/REC-xml/#NT-Char:
# Char ::= #x9 | #xA | #xD | [#x20-#xD7FF] | [#xE000-#xFFFD] | [#x10000-#x10FFFF]
INVALID_XML10_CHARS = /[^\x09\x0A\x0D\x20-\uD7FF\uE000-\uFFFD\u10000-\u10FFFF]/.freeze
INVALID_XML10_CHARS = /[^\x09\x0A\x0D\x20-\uD7FF\uE000-\uFFFD\u{10000}-\u{10FFFF}]/.freeze

# ST_Xstring escaping
ESCAPE_CHAR = lambda { |c| '_x%04X_'.freeze % c.ord }.freeze
Expand Down
6 changes: 6 additions & 0 deletions test/xlsxtream/xml_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,11 @@ def test_escape_value_invalid_xml_chars
expected = 'The _x0007_ rings_x0000__xFFFE__xFFFF_'
assert_equal expected, XML.escape_value(unsafe_value)
end

def test_escape_value_valid_xml_chars
safe_value = "\u{10000}\u{10FFFF}"
expected = safe_value
assert_equal expected, XML.escape_value(safe_value)
end
end
end

0 comments on commit 229ab50

Please sign in to comment.