From 9f71b1ec7b90987cd4e3d8dca3ac32b4560f325d Mon Sep 17 00:00:00 2001 From: Tero Tasanen Date: Sun, 14 Sep 2014 12:02:02 +0300 Subject: [PATCH] Ignore casing when testing for html void elements Fixes #36 --- lib/oga/xml/lexer.rb | 2 +- spec/oga/xml/parser/html_void_elements_spec.rb | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/lib/oga/xml/lexer.rb b/lib/oga/xml/lexer.rb index 655d36e..8021bdc 100644 --- a/lib/oga/xml/lexer.rb +++ b/lib/oga/xml/lexer.rb @@ -347,7 +347,7 @@ module Oga # Called on the closing `>` of the open tag of an element. # def on_element_open_end - if html? and HTML_VOID_ELEMENTS.include?(current_element) + if html? and HTML_VOID_ELEMENTS.include?(current_element.downcase) add_token(:T_ELEM_END) @elements.pop end diff --git a/spec/oga/xml/parser/html_void_elements_spec.rb b/spec/oga/xml/parser/html_void_elements_spec.rb index 9166746..674fe4f 100644 --- a/spec/oga/xml/parser/html_void_elements_spec.rb +++ b/spec/oga/xml/parser/html_void_elements_spec.rb @@ -29,6 +29,24 @@ describe Oga::XML::Parser do end end + context 'void elements with different casing' do + before :all do + @node_lc = parse('
', html: true).children[0] + @node_uc = parse('
', html: true).children[0] + end + + example 'parse void elements with different casing' do + @node_lc.is_a?(Oga::XML::Element).should == true + @node_uc.is_a?(Oga::XML::Element).should == true + end + + example 'set the name of the void element to match casing' do + @node_lc.name.should == 'br' + @node_uc.name.should == 'BR' + end + + end + context 'void elements with attributes' do before :all do @node = parse('', :html => true).children[0]