-
Notifications
You must be signed in to change notification settings - Fork 98
Fix xpath functions related to names #343
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -22,8 +22,10 @@ def initialize | |||||||||||||||||||||||||
| :variables, | ||||||||||||||||||||||||||
| :variables=, | ||||||||||||||||||||||||||
| :context=, | ||||||||||||||||||||||||||
| :get_namespace, | ||||||||||||||||||||||||||
| :target_named_node, | ||||||||||||||||||||||||||
| :send, | ||||||||||||||||||||||||||
| :compare_language, | ||||||||||||||||||||||||||
| :string_value, | ||||||||||||||||||||||||||
| ] | ||||||||||||||||||||||||||
| class << self | ||||||||||||||||||||||||||
| def method_added(name) | ||||||||||||||||||||||||||
|
|
@@ -61,41 +63,27 @@ def id( object ) | |||||||||||||||||||||||||
| end | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| def local_name(node_set=nil) | ||||||||||||||||||||||||||
| get_namespace(node_set) do |node| | ||||||||||||||||||||||||||
| return node.local_name | ||||||||||||||||||||||||||
| end | ||||||||||||||||||||||||||
| "" | ||||||||||||||||||||||||||
| target_named_node(node_set)&.local_name || "" | ||||||||||||||||||||||||||
| end | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| def namespace_uri( node_set=nil ) | ||||||||||||||||||||||||||
| get_namespace( node_set ) do |node| | ||||||||||||||||||||||||||
| return node.namespace | ||||||||||||||||||||||||||
| end | ||||||||||||||||||||||||||
| "" | ||||||||||||||||||||||||||
| target_named_node(node_set)&.namespace || "" | ||||||||||||||||||||||||||
| end | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| def name( node_set=nil ) | ||||||||||||||||||||||||||
| get_namespace( node_set ) do |node| | ||||||||||||||||||||||||||
| return node.expanded_name | ||||||||||||||||||||||||||
| end | ||||||||||||||||||||||||||
| "" | ||||||||||||||||||||||||||
| target_named_node(node_set)&.expanded_name || "" | ||||||||||||||||||||||||||
| end | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| # Helper method. | ||||||||||||||||||||||||||
| def get_namespace( node_set = nil ) | ||||||||||||||||||||||||||
| if node_set == nil | ||||||||||||||||||||||||||
| yield @context[:node] if @context[:node].respond_to?(:namespace) | ||||||||||||||||||||||||||
| else | ||||||||||||||||||||||||||
| if node_set.kind_of? Array | ||||||||||||||||||||||||||
| result = [] | ||||||||||||||||||||||||||
| XPathParser.sort(node_set).each do |node| | ||||||||||||||||||||||||||
| result << yield(node) if node.respond_to?(:namespace) | ||||||||||||||||||||||||||
| end | ||||||||||||||||||||||||||
| result | ||||||||||||||||||||||||||
| elsif node_set.respond_to? :namespace | ||||||||||||||||||||||||||
| yield node_set | ||||||||||||||||||||||||||
| def target_named_node(node_set = nil) | ||||||||||||||||||||||||||
| node = | ||||||||||||||||||||||||||
| case node_set | ||||||||||||||||||||||||||
| when nil | ||||||||||||||||||||||||||
| @context[:node] | ||||||||||||||||||||||||||
| when Array | ||||||||||||||||||||||||||
| XPathParser.sort(node_set).first | ||||||||||||||||||||||||||
| end | ||||||||||||||||||||||||||
|
Comment on lines
+81
to
85
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There is regression.
> doc = REXML::Document.new("<root xmlns:x='http://example.com/x/'><x:child/></root>")
> REXML::Functions.local_name(doc.root.elements[1]) #=> "child"
> REXML::Functions.local_name("not a node") #=> ""
> doc = REXML::Document.new("<root xmlns:x='http://example.com/x/'><x:child/></root>")
> REXML::Functions.local_name(doc.root.elements[1]) #=> ""
> REXML::Functions.local_name("not a node") #=> ""
Suggested change
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is it really a regression? I think it's a dead branch which should be cleaned up.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
This change is not a regression. https://docs.ruby-lang.org/ja/latest/class/REXML=3a=3aFunctions.html
(I'm sorry for writing in Japanese.)
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I rewrote the code so that it doesn't use
> doc = REXML::Document.new("<root xmlns:x='http://example.com/x/'><x:child/></root>")
> child = doc.root.elements[1] #=> <x:child/>
> REXML::XPath.match(doc, "local-name($x)", nil, { "x" => child }) #=> ["child"]
> REXML::XPath.match(doc, "local-name('not a node')") #=> [""]
> doc = REXML::Document.new("<root xmlns:x='http://example.com/x/'><x:child/></root>")
> child = doc.root.elements[1] #=> <x:child/>
> REXML::XPath.match(doc, "local-name($x)", nil, { "x" => child }) #=> [""]
> REXML::XPath.match(doc, "local-name('not a node')") #=> [""]
However, I agree that “single nodes do not need to be considered.”
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The variable in the code below is invalid for now. REXML::XPath.match(doc, "local-name($x)", nil, { "x" => child })Example: REXML::XPath.match(doc, "($x)/root", nil, { "x" => [doc] })
# => [<root xmlns:x='http://example.com/x/'> ... </>]
REXML::XPath.match(doc, "($x)/root", nil, { "x" => doc })
# => [<UNDEFINED> ... </>]It will be valid in #342 (comment)
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
After rebasing, I confirmed that it works as expected. |
||||||||||||||||||||||||||
| end | ||||||||||||||||||||||||||
| node if node.respond_to?(:namespace) | ||||||||||||||||||||||||||
| end | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| # A node-set is converted to a string by returning the string-value of the | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
Uh oh!
There was an error while loading. Please reload this page.