Fixed XML entity encoding/decoding ordering.
Thanks to @krasnoukhov for providing the initial patch, which this commit is largely based on. This fixes #49.
This commit is contained in:
parent
675eb562e2
commit
ad4f650c5d
|
@ -4,15 +4,15 @@ module Oga
|
|||
##
|
||||
# Hash containing XML entities and the corresponding characters.
|
||||
#
|
||||
# The `&` mapping must come first to ensure proper conversion of non
|
||||
# The `&` mapping must come last to ensure proper conversion of non
|
||||
# encoded to encoded forms (see {Oga::XML::Text#to_xml}).
|
||||
#
|
||||
# @return [Hash]
|
||||
#
|
||||
DECODE_MAPPING = {
|
||||
'&' => '&',
|
||||
'<' => '<',
|
||||
'>' => '>'
|
||||
'>' => '>',
|
||||
'&' => '&'
|
||||
}
|
||||
|
||||
##
|
||||
|
@ -20,7 +20,11 @@ module Oga
|
|||
#
|
||||
# @return [Hash]
|
||||
#
|
||||
ENCODE_MAPPING = DECODE_MAPPING.invert
|
||||
ENCODE_MAPPING = {
|
||||
'&' => '&',
|
||||
'>' => '>',
|
||||
'<' => '<'
|
||||
}
|
||||
|
||||
##
|
||||
# Decodes XML entities.
|
||||
|
|
|
@ -13,6 +13,22 @@ describe Oga::XML::Entities do
|
|||
example 'decode > into >' do
|
||||
described_class.decode('>').should == '>'
|
||||
end
|
||||
|
||||
example 'decode &gt; into >' do
|
||||
described_class.decode('&gt;').should == '>'
|
||||
end
|
||||
|
||||
example 'decode &&gt; into &>' do
|
||||
described_class.decode('&&gt;').should == '&>'
|
||||
end
|
||||
|
||||
example 'decode &lt; into <' do
|
||||
described_class.decode('&lt;').should == '<'
|
||||
end
|
||||
|
||||
example 'decode &&lt; into &<' do
|
||||
described_class.decode('&&lt;').should == '&<'
|
||||
end
|
||||
end
|
||||
|
||||
context 'encode' do
|
||||
|
@ -27,5 +43,13 @@ describe Oga::XML::Entities do
|
|||
example 'encode > as >' do
|
||||
described_class.encode('>').should == '>'
|
||||
end
|
||||
|
||||
example 'encode > as &gt;' do
|
||||
described_class.encode('>').should == '&gt;'
|
||||
end
|
||||
|
||||
example 'encode < as &lt;' do
|
||||
described_class.encode('<').should == '&lt;'
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue