From 9f71b1ec7b90987cd4e3d8dca3ac32b4560f325d Mon Sep 17 00:00:00 2001 From: Tero Tasanen Date: Sun, 14 Sep 2014 12:02:02 +0300 Subject: [PATCH 1/4] 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] From 9c8dd60f923d3efdbb3f3ea24e0da923749128c5 Mon Sep 17 00:00:00 2001 From: Tero Tasanen Date: Sun, 14 Sep 2014 14:14:51 +0300 Subject: [PATCH 2/4] Fix test cases - Remove duplicate tests - use parse_html helper --- spec/oga/xml/parser/html_void_elements_spec.rb | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/spec/oga/xml/parser/html_void_elements_spec.rb b/spec/oga/xml/parser/html_void_elements_spec.rb index 674fe4f..24a661e 100644 --- a/spec/oga/xml/parser/html_void_elements_spec.rb +++ b/spec/oga/xml/parser/html_void_elements_spec.rb @@ -31,20 +31,16 @@ describe Oga::XML::Parser do context 'void elements with different casing' do before :all do - @node_lc = parse('
', html: true).children[0] - @node_uc = parse('
', html: true).children[0] + @node_uc = parse_html('
').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 From d0f48e0e3c090804faf18f3480616989d103b462 Mon Sep 17 00:00:00 2001 From: Tero Tasanen Date: Sun, 14 Sep 2014 14:20:58 +0300 Subject: [PATCH 3/4] Added a lexer test case for uppercase void elements --- spec/oga/xml/lexer/html_void_elements_spec.rb | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/spec/oga/xml/lexer/html_void_elements_spec.rb b/spec/oga/xml/lexer/html_void_elements_spec.rb index aac509f..8e3337f 100644 --- a/spec/oga/xml/lexer/html_void_elements_spec.rb +++ b/spec/oga/xml/lexer/html_void_elements_spec.rb @@ -10,6 +10,14 @@ describe Oga::XML::Lexer do ] end + example 'lex a upper case void element' do + lex('
', html: true).should == [ + [:T_ELEM_START, nil, 1], + [:T_ELEM_NAME, "BR", 1], + [:T_ELEM_END, nil, 1] + ] + end + example 'lex text after a void element' do lex('foo', :html => true).should == [ [:T_ELEM_START, nil, 1], From 3c930433c476125b18c53b6d54b43e5ae71246cb Mon Sep 17 00:00:00 2001 From: Tero Tasanen Date: Sun, 14 Sep 2014 15:04:15 +0300 Subject: [PATCH 4/4] Change Hash syntax to be consistent with other tests --- spec/oga/xml/lexer/html_void_elements_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/oga/xml/lexer/html_void_elements_spec.rb b/spec/oga/xml/lexer/html_void_elements_spec.rb index 8e3337f..69fc97a 100644 --- a/spec/oga/xml/lexer/html_void_elements_spec.rb +++ b/spec/oga/xml/lexer/html_void_elements_spec.rb @@ -11,7 +11,7 @@ describe Oga::XML::Lexer do end example 'lex a upper case void element' do - lex('
', html: true).should == [ + lex('
', :html => true).should == [ [:T_ELEM_START, nil, 1], [:T_ELEM_NAME, "BR", 1], [:T_ELEM_END, nil, 1]