From f1316c50fb6a3ee368b0438a8757d1d9d1023782 Mon Sep 17 00:00:00 2001 From: Yorick Peterse Date: Wed, 5 Nov 2014 00:35:47 +0100 Subject: [PATCH] Allow XPath idents to start with an underscore. This is valid in XML so XPath should support it as well. --- lib/oga/xpath/lexer.rl | 2 +- spec/oga/xpath/lexer/general_spec.rb | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/oga/xpath/lexer.rl b/lib/oga/xpath/lexer.rl index bddf229..4fb91ef 100644 --- a/lib/oga/xpath/lexer.rl +++ b/lib/oga/xpath/lexer.rl @@ -194,7 +194,7 @@ module Oga # Identifiers are used for element names, namespaces, attribute names, # etc. Identifiers have to start with a letter. - identifier = '*' | [a-zA-Z*]+ [a-zA-Z\-_0-9]*; + identifier = '*' | [a-zA-Z*_]+ [a-zA-Z\-_0-9]*; action emit_identifier { emit(:T_IDENT, ts, te) diff --git a/spec/oga/xpath/lexer/general_spec.rb b/spec/oga/xpath/lexer/general_spec.rb index 439c55a..9298b4c 100644 --- a/spec/oga/xpath/lexer/general_spec.rb +++ b/spec/oga/xpath/lexer/general_spec.rb @@ -6,6 +6,10 @@ describe Oga::XPath::Lexer do lex_xpath('/foo').should == [[:T_SLASH, nil], [:T_IDENT, 'foo']] end + example 'lex a simple expression with a test starting with an underscore' do + lex_xpath('/_foo').should == [[:T_SLASH, nil], [:T_IDENT, '_foo']] + end + example 'lex a node test using a namespace' do lex_xpath('/foo:bar').should == [ [:T_SLASH, nil],