From 0800654c962c20fb139a389245359bca9952dcd1 Mon Sep 17 00:00:00 2001 From: Yorick Peterse Date: Fri, 3 Apr 2015 00:46:37 +0200 Subject: [PATCH] Support lexing or carriage returns Fixes #89. --- ext/ragel/base_lexer.rl | 2 +- spec/oga/xml/lexer/elements_spec.rb | 8 ++++++++ spec/oga/xml/lexer/general_spec.rb | 10 +++++++++- 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/ext/ragel/base_lexer.rl b/ext/ragel/base_lexer.rl index 739c15c..a04140f 100644 --- a/ext/ragel/base_lexer.rl +++ b/ext/ragel/base_lexer.rl @@ -46,7 +46,7 @@ # stack. # - newline = '\n' | '\r\n'; + newline = '\r\n' | '\n' | '\r'; action count_newlines { if ( fc == '\n' ) lines++; diff --git a/spec/oga/xml/lexer/elements_spec.rb b/spec/oga/xml/lexer/elements_spec.rb index 59a76ec..2450232 100644 --- a/spec/oga/xml/lexer/elements_spec.rb +++ b/spec/oga/xml/lexer/elements_spec.rb @@ -41,6 +41,14 @@ describe Oga::XML::Lexer do [:T_ELEM_END, nil, 2] ] end + + it 'lexes an element with a carriage return in the open tag' do + lex("

").should == [ + [:T_ELEM_START, nil, 1], + [:T_ELEM_NAME, 'p', 1], + [:T_ELEM_END, nil, 2] + ] + end end describe 'elements with attributes' do diff --git a/spec/oga/xml/lexer/general_spec.rb b/spec/oga/xml/lexer/general_spec.rb index f9b3105..bc02a11 100644 --- a/spec/oga/xml/lexer/general_spec.rb +++ b/spec/oga/xml/lexer/general_spec.rb @@ -10,10 +10,18 @@ describe Oga::XML::Lexer do lex(' ').should == [[:T_TEXT, ' ', 1]] end - it 'lexes a newline' do + it 'lexes a Unix newline' do lex("\n").should == [[:T_TEXT, "\n", 1]] end + it 'lexes a Windows newline' do + lex("\r\n").should == [[:T_TEXT, "\r\n", 1]] + end + + it 'lexes a carriage return' do + lex("\r").should == [[:T_TEXT, "\r", 1]] + end + it 'lexes text followed by a newline' do lex("foo\n").should == [[:T_TEXT, "foo\n", 1]] end