Merge pull request #67 from krasnoukhov/xml-entities

Add missing entities to the decode/encode lists
This commit is contained in:
Yorick Peterse 2014-11-21 01:12:24 +01:00
commit a10fe855d7
2 changed files with 61 additions and 8 deletions

View File

@ -11,8 +11,15 @@ module Oga
#
DECODE_MAPPING = {
'&lt;' => '<',
'&#60;' => '<',
'&gt;' => '>',
'&amp;' => '&'
'&#62;' => '>',
'&apos;' => "'",
'&#39;' => "'",
'&quot;' => '"',
'&#34;' => '"',
'&amp;' => '&',
'&#38;' => '&',
}
##
@ -22,8 +29,10 @@ module Oga
#
ENCODE_MAPPING = {
'&' => '&amp;',
'"' => '&quot;',
"'" => '&apos;',
'>' => '&gt;',
'<' => '&lt;'
'<' => '&lt;',
}
##

View File

@ -2,10 +2,6 @@ require 'spec_helper'
describe Oga::XML::Entities do
context 'decode' do
example 'decode &amp; into &' do
described_class.decode('&amp;').should == '&'
end
example 'decode &lt; into <' do
described_class.decode('&lt;').should == '<'
end
@ -14,6 +10,46 @@ describe Oga::XML::Entities do
described_class.decode('&gt;').should == '>'
end
example "decode &apos; into '" do
described_class.decode('&apos;').should == "'"
end
example 'decode &quot; into "' do
described_class.decode('&quot;').should == '"'
end
example 'decode &amp; into &' do
described_class.decode('&amp;').should == '&'
end
example 'decode &#60; into <' do
described_class.decode('&#60;').should == '<'
end
example 'decode &#62; into >' do
described_class.decode('&#62;').should == '>'
end
example "decode &#39; into '" do
described_class.decode('&#39;').should == "'"
end
example 'decode &#34; into "' do
described_class.decode('&#34;').should == '"'
end
example 'decode &#38; into &' do
described_class.decode('&#38;').should == '&'
end
example 'decode &#38;#60; into &#60;' do
described_class.decode('&#38;#60;').should == '&#60;'
end
example 'decode &#38;#38; into &#38;' do
described_class.decode('&#38;#38;').should == '&#38;'
end
example 'decode &amp;gt; into &gt;' do
described_class.decode('&amp;gt;').should == '&gt;'
end
@ -36,6 +72,14 @@ describe Oga::XML::Entities do
described_class.encode('&').should == '&amp;'
end
example 'encode " as &quot;' do
described_class.encode('"').should == '&quot;'
end
example "encode ' as &apos;" do
described_class.encode("'").should == '&apos;'
end
example 'encode < as &lt;' do
described_class.encode('<').should == '&lt;'
end