diff --git a/lib/oga/xml/entities.rb b/lib/oga/xml/entities.rb index 3fcef2b..6a6849d 100644 --- a/lib/oga/xml/entities.rb +++ b/lib/oga/xml/entities.rb @@ -10,9 +10,16 @@ module Oga # @return [Hash] # DECODE_MAPPING = { - '<' => '<', - '>' => '>', - '&' => '&' + '<' => '<', + '<' => '<', + '>' => '>', + '>' => '>', + ''' => "'", + ''' => "'", + '"' => '"', + '"' => '"', + '&' => '&', + '&' => '&', } ## @@ -22,8 +29,10 @@ module Oga # ENCODE_MAPPING = { '&' => '&', + '"' => '"', + "'" => ''', '>' => '>', - '<' => '<' + '<' => '<', } ## diff --git a/spec/oga/xml/entities_spec.rb b/spec/oga/xml/entities_spec.rb index 6a080ff..fbfce69 100644 --- a/spec/oga/xml/entities_spec.rb +++ b/spec/oga/xml/entities_spec.rb @@ -2,10 +2,6 @@ require 'spec_helper' describe Oga::XML::Entities do context 'decode' do - example 'decode & into &' do - described_class.decode('&').should == '&' - end - example 'decode < into <' do described_class.decode('<').should == '<' end @@ -14,6 +10,46 @@ describe Oga::XML::Entities do described_class.decode('>').should == '>' end + example "decode ' into '" do + described_class.decode(''').should == "'" + end + + example 'decode " into "' do + described_class.decode('"').should == '"' + end + + example 'decode & into &' do + described_class.decode('&').should == '&' + end + + example 'decode < into <' do + described_class.decode('<').should == '<' + end + + example 'decode > into >' do + described_class.decode('>').should == '>' + end + + example "decode ' into '" do + described_class.decode(''').should == "'" + end + + example 'decode " into "' do + described_class.decode('"').should == '"' + end + + example 'decode & into &' do + described_class.decode('&').should == '&' + end + + example 'decode &#60; into <' do + described_class.decode('&#60;').should == '<' + end + + example 'decode &#38; into &' do + described_class.decode('&#38;').should == '&' + end + example 'decode &gt; into >' do described_class.decode('&gt;').should == '>' end @@ -36,6 +72,14 @@ describe Oga::XML::Entities do described_class.encode('&').should == '&' end + example 'encode " as "' do + described_class.encode('"').should == '"' + end + + example "encode ' as '" do + described_class.encode("'").should == ''' + end + example 'encode < as <' do described_class.encode('<').should == '<' end