diff --git a/lib/rexml/parsers/baseparser.rb b/lib/rexml/parsers/baseparser.rb
index 275372ee..02759e70 100644
--- a/lib/rexml/parsers/baseparser.rb
+++ b/lib/rexml/parsers/baseparser.rb
@@ -511,7 +511,11 @@ def normalize( input, entities=nil, entity_filter=nil )
# Unescapes all possible entities
def unnormalize( string, entities=nil, filter=nil )
- rv = string.gsub( Private::CARRIAGE_RETURN_NEWLINE_PATTERN, "\n" )
+ if string.include?("\r")
+ rv = string.gsub( Private::CARRIAGE_RETURN_NEWLINE_PATTERN, "\n" )
+ else
+ rv = string.dup
+ end
matches = rv.scan( REFERENCE_RE )
return rv if matches.size == 0
rv.gsub!( Private::CHARACTER_REFERENCES ) {
diff --git a/test/test_pullparser.rb b/test/test_pullparser.rb
index b6a48c93..652a613c 100644
--- a/test/test_pullparser.rb
+++ b/test/test_pullparser.rb
@@ -63,7 +63,7 @@ def test_entity_replacement
end
def test_character_references
- source = 'AB'
+ source = "A\r\nB"
parser = REXML::Parsers::PullParser.new( source )
element_name = ''
while parser.has_next?
@@ -71,12 +71,16 @@ def test_character_references
case event.event_type
when :start_element
element_name = event[0]
+ when :end_element
+ element_name = nil
when :text
case element_name
when 'a'
assert_equal('A', event[1])
when 'b'
assert_equal('B', event[1])
+ else
+ assert_equal("\n", event[1])
end
end
end