Fixes #118 - decoding invalid entities.

Previous regular expression was too greedy in terms of matching
letters from outside of A-F hex scope, and matching letters when
not in hex mode.
This commit is contained in:
Jakub Pawlowicz authored and Yorick Peterse committed 2015-06-30 17:56:26 +02:00
1 parent 8990a62224
commit 6fc3ef425b
2 files changed
+14 -2

No files matched your search

+2 -2
View File
@@ -63,7 +63,7 @@ module Oga
#
# @return [Regexp]
#
CODEPOINT_ENTITY = /&#(x)?([a-zA-Z0-9]+);/
CODEPOINT_ENTITY = /&#(x[a-fA-F0-9]+|\d+);/
##
# @return [Regexp]
@@ -90,7 +90,7 @@ module Oga
if input.include?(AMPERSAND)
input = input.gsub(CODEPOINT_ENTITY) do |match|
[$1 ? Integer($2, 16) : Integer($2, 10)].pack('U*')
[$1.start_with?('x') ? Integer($1[1..-1], 16) : Integer($1, 10)].pack('U*')
end
end