Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions lib/rexml/functions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,17 @@ def Functions::local_name(node_set=nil)
end

def Functions::namespace_uri( node_set=nil )
get_namespace( node_set ) {|node| node.namespace}
get_namespace( node_set ) do |node|
return node.namespace
end
""
Comment on lines +77 to +80
Comment on lines +77 to +80
end

def Functions::name( node_set=nil )
get_namespace( node_set ) do |node|
node.expanded_name
return node.expanded_name
end
""
Comment on lines 84 to +87
end

# Helper method.
Expand Down
9 changes: 3 additions & 6 deletions lib/rexml/xpath_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ def expr( path_stack, nodeset, context=nil )
end
when :variable
var_name = path_stack.shift
return [@variables[var_name]]
return @variables[var_name]

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Returning nil may cause unintentional behavior. However, it was returning [nil] before, and it may also cause problem, so basically nothing has changed.

In XPath 1.0, only string | number | boolean | nodeset are allowed.
In Nokogiri, using undefined variable will raise Undefined variable: $foo (Nokogiri::XML::XPath::SyntaxError).
In JavaScript's document.execute, all variables are bound to empty string.

Ideally, REXML should validate variables somewhere, and need to decide how to handle undefined variables: fallback or raise. Although changing/deciding this may be out of scope of this pull request.

Ref: https://www.w3.org/TR/1999/REC-xpath-19991116/#section-Basics

A VariableReference evaluates to the value to which the variable name is bound in the set of variable bindings in the context. It is an error if the variable name is not bound to any value in the set of variable bindings in the expression context.


when :eq, :neq, :lt, :lteq, :gt, :gteq
left = expr( path_stack.shift, nodeset.dup, context )
Expand Down Expand Up @@ -533,16 +533,13 @@ def evaluate_predicate(expression, nodesets)
subcontext[:position] = position
result = expr(expression.dclone, [node], subcontext)
trace(:predicate_evaluate, expression, node, subcontext, result) if @debug
result = result[0] if result.kind_of? Array and result.length == 1
if result.kind_of? Numeric
if result == position
new_nodeset << node
end
elsif result.instance_of? Array
if result.size > 0 and result.inject(false) {|k,s| s or k}
if result.size > 0
new_nodeset << node
end
if result.size > 0
new_nodeset << node
end
Comment on lines 534 to 543
else
if result
Expand Down
Loading