diff --git a/lib/rexml/parsers/baseparser.rb b/lib/rexml/parsers/baseparser.rb
index 84fc5ca5..afc15db9 100644
--- a/lib/rexml/parsers/baseparser.rb
+++ b/lib/rexml/parsers/baseparser.rb
@@ -61,7 +61,7 @@ class BaseParser
XMLDECL_PATTERN = /<\?xml\s+(.*?)\?>/um
INSTRUCTION_START = /\A<\?/u
INSTRUCTION_PATTERN = /<\?#{NAME}(\s+.*?)?\?>/um
- TAG_MATCH = /^<((?>#{QNAME_STR}))/um
+ TAG_MATCH = /\A<((?>#{QNAME_STR}))/um
CLOSE_MATCH = /^\s*<\/(#{QNAME_STR})\s*>/um
VERSION = /\bversion\s*=\s*["'](.*?)['"]/um
diff --git a/test/parse/test_element.rb b/test/parse/test_element.rb
index 7322e0eb..1c4258c7 100644
--- a/test/parse/test_element.rb
+++ b/test/parse/test_element.rb
@@ -46,6 +46,19 @@ def test_empty_namespace_attribute_name
DETAIL
end
+
+ def test_garbage_less_than_before_root_element_at_line_start
+ exception = assert_raise(REXML::ParseException) do
+ parse("<\n")
+ end
+ assert_equal(<<-DETAIL.chomp, exception.to_s)
+malformed XML: missing tag start
+Line: 2
+Position: 6
+Last 80 unconsumed characters:
+<
+ DETAIL
+ end
end
end
end