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],