From 853d804f3468c9f54c222568a7faedf736f8dc1a Mon Sep 17 00:00:00 2001 From: Yorick Peterse Date: Mon, 20 Apr 2015 00:13:15 +0200 Subject: [PATCH] Decoding of zero padded XML entities This would previously fail due to the lack of an explicit base to use for Integer(). --- lib/oga/xml/entities.rb | 2 +- spec/oga/xml/entities_spec.rb | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/oga/xml/entities.rb b/lib/oga/xml/entities.rb index 470036e..66a5615 100644 --- a/lib/oga/xml/entities.rb +++ b/lib/oga/xml/entities.rb @@ -72,7 +72,7 @@ module Oga if input.include?(AMPERSAND) input = input.gsub(CODEPOINT_ENTITY) do |match| - [$1 ? Integer($2, 16) : Integer($2)].pack('U') + [$1 ? Integer($2, 16) : Integer($2, 10)].pack('U*') end end diff --git a/spec/oga/xml/entities_spec.rb b/spec/oga/xml/entities_spec.rb index 68bf4d3..11161a1 100644 --- a/spec/oga/xml/entities_spec.rb +++ b/spec/oga/xml/entities_spec.rb @@ -69,6 +69,10 @@ describe Oga::XML::Entities do it 'decodes < into <' do described_class.decode('<').should == '<' end + + it 'decodes numeric entities starting with a 0' do + described_class.decode('&').should == '&' + end end describe 'encode' do