Reject underscored XPath function names - #366
Conversation
|
I want to keep backward compatibility as much as possible. How about rejecting |
|
Updated this so underscored function names remain accepted by default and are rejected only when the existing Ran:
|
| #arry << @variables[ varname ] | ||
| when /^(\w[-\w]*)(?:\()/ | ||
| fname = $1 | ||
| return path if @strict && fname.include?("_") |
There was a problem hiding this comment.
The mechanism that this return path rejects the xpath, is complicated. (See LocationPath → RelativeLocationPath → NodeTest called when 'local_name()' is passed)
I think underscored function names are invalid not because it has underscore, but because it's not registered as a function in XPath 1.0 spec.
Both examples in the code below is in the same situation: using unknown function, so the result (return value or raised error) should be the same.
REXML::XPath.match(REXML::Document.new('<root/>'), 'local_name()')
REXML::XPath.match(REXML::Document.new('<root/>'), 'localname()')From a viewpoint of module's responsibility, I personally think this check shouldn't be done in REXML::Parsers:XPathParser, but in one of:
REXML::XPathParser: layer that converts'-'to'_', function name to a method nameREXML::FunctionsClass: layer that knows all available functions, checks if a method name is registered as a function
Summary
Fixes #352.
Reject XPath function names containing underscores instead of treating them as
aliases for hyphenated standard functions. Standard names such as
local-name()continue to parse normally.Changes
coverage.
Testing
ruby -Itest -Ilib test/parser/test_xpath.rb --name=test_function_with_underscorerake test