From 3b2279e4106d129ffd36ce249e1f80fcf02d443b Mon Sep 17 00:00:00 2001 From: Yorick Peterse Date: Thu, 7 Aug 2014 20:16:46 +0200 Subject: [PATCH] Don't create empty Namespace nodes. --- lib/oga/xml/parser.y | 6 +++++- spec/oga/xml/parser/elements_spec.rb | 4 ++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/oga/xml/parser.y b/lib/oga/xml/parser.y index f7de1c7..9e12bc1 100644 --- a/lib/oga/xml/parser.y +++ b/lib/oga/xml/parser.y @@ -338,8 +338,12 @@ Unexpected #{name} with value #{value.inspect} on line #{@line}: # @return [Oga::XML::Element] # def on_element(namespace, name, attributes = {}) + if namespace + namespace = Namespace.new(:name => namespace) + end + element = Element.new( - :namespace => Namespace.new(:name => namespace), + :namespace => namespace, :name => name, :attributes => attributes ) diff --git a/spec/oga/xml/parser/elements_spec.rb b/spec/oga/xml/parser/elements_spec.rb index 61c5285..10fc35a 100644 --- a/spec/oga/xml/parser/elements_spec.rb +++ b/spec/oga/xml/parser/elements_spec.rb @@ -13,6 +13,10 @@ describe Oga::XML::Parser do example 'set the name of the element' do @element.name.should == 'p' end + + example 'do not set a namespace' do + @element.namespace.nil?.should == true + end end context 'elements with namespaces' do