From 276a5ab83b787ab3a615369aeeaea23496e3a424 Mon Sep 17 00:00:00 2001 From: Yorick Peterse Date: Mon, 25 Aug 2014 09:42:51 +0200 Subject: [PATCH] Support for lexing empty XPath strings. --- lib/oga/xpath/lexer.rl | 4 ++-- spec/oga/xpath/lexer/strings_spec.rb | 21 +++++++++++++++++++++ 2 files changed, 23 insertions(+), 2 deletions(-) create mode 100644 spec/oga/xpath/lexer/strings_spec.rb diff --git a/lib/oga/xpath/lexer.rl b/lib/oga/xpath/lexer.rl index 640ccbf..5cdf58e 100644 --- a/lib/oga/xpath/lexer.rl +++ b/lib/oga/xpath/lexer.rl @@ -201,8 +201,8 @@ module Oga dquote = '"'; squote = "'"; - string_dquote = (dquote ^dquote+ dquote); - string_squote = (squote ^squote+ squote); + string_dquote = (dquote ^dquote* dquote); + string_squote = (squote ^squote* squote); string = string_dquote | string_squote; diff --git a/spec/oga/xpath/lexer/strings_spec.rb b/spec/oga/xpath/lexer/strings_spec.rb new file mode 100644 index 0000000..263fee6 --- /dev/null +++ b/spec/oga/xpath/lexer/strings_spec.rb @@ -0,0 +1,21 @@ +require 'spec_helper' + +describe Oga::XPath::Lexer do + context 'strings' do + example 'lex a double quoted string' do + lex_xpath('"foo"').should == [[:T_STRING, 'foo']] + end + + example 'lex a single quoted string' do + lex_xpath("'foo'").should == [[:T_STRING, 'foo']] + end + + example 'lex an empty double quoted string' do + lex_xpath('""').should == [[:T_STRING, '']] + end + + example 'lex an empty single quoted string' do + lex_xpath("''").should == [[:T_STRING, '']] + end + end +end