Skip to content

Commit f7bab89

Browse files
koumame
authored andcommitted
Fix a bug that invalid element end may be accepted
HackerOne: HO-1104077 It's caused by ignoring garbage before "\n</NAME>". Reported by Juho Nurminen. Thanks!!!
1 parent 6a250d2 commit f7bab89

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

lib/rexml/parsers/baseparser.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ class BaseParser
6262
INSTRUCTION_START = /\A<\?/u
6363
INSTRUCTION_PATTERN = /<\?#{NAME}(\s+.*?)?\?>/um
6464
TAG_MATCH = /\A<((?>#{QNAME_STR}))/um
65-
CLOSE_MATCH = /^\s*<\/(#{QNAME_STR})\s*>/um
65+
CLOSE_MATCH = /\A\s*<\/(#{QNAME_STR})\s*>/um
6666

6767
VERSION = /\bversion\s*=\s*["'](.*?)['"]/um
6868
ENCODING = /\bencoding\s*=\s*["'](.*?)['"]/um

test/parse/test_element.rb

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,19 @@ def test_garbage_less_than_before_root_element_at_line_start
5959
< <x/>
6060
DETAIL
6161
end
62+
63+
def test_garbage_less_than_slash_before_end_tag_at_line_start
64+
exception = assert_raise(REXML::ParseException) do
65+
parse("<x></\n</x>")
66+
end
67+
assert_equal(<<-DETAIL.chomp, exception.to_s)
68+
Missing end tag for 'x'
69+
Line: 2
70+
Position: 10
71+
Last 80 unconsumed characters:
72+
</ </x>
73+
DETAIL
74+
end
6275
end
6376
end
6477
end

0 commit comments

Comments
 (0)