diff --git a/lib/rexml/parsers/baseparser.rb b/lib/rexml/parsers/baseparser.rb
index afc15db9..ca29b4a9 100644
--- a/lib/rexml/parsers/baseparser.rb
+++ b/lib/rexml/parsers/baseparser.rb
@@ -62,7 +62,7 @@ class BaseParser
INSTRUCTION_START = /\A<\?/u
INSTRUCTION_PATTERN = /<\?#{NAME}(\s+.*?)?\?>/um
TAG_MATCH = /\A<((?>#{QNAME_STR}))/um
- CLOSE_MATCH = /^\s*<\/(#{QNAME_STR})\s*>/um
+ CLOSE_MATCH = /\A\s*<\/(#{QNAME_STR})\s*>/um
VERSION = /\bversion\s*=\s*["'](.*?)['"]/um
ENCODING = /\bencoding\s*=\s*["'](.*?)['"]/um
diff --git a/test/parse/test_element.rb b/test/parse/test_element.rb
index 1c4258c7..9f172a28 100644
--- a/test/parse/test_element.rb
+++ b/test/parse/test_element.rb
@@ -59,6 +59,19 @@ def test_garbage_less_than_before_root_element_at_line_start
<
DETAIL
end
+
+ def test_garbage_less_than_slash_before_end_tag_at_line_start
+ exception = assert_raise(REXML::ParseException) do
+ parse("\n")
+ end
+ assert_equal(<<-DETAIL.chomp, exception.to_s)
+Missing end tag for 'x'
+Line: 2
+Position: 10
+Last 80 unconsumed characters:
+
+ DETAIL
+ end
end
end
end