1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

merge revision(s) 59584: [Backport #13850]

REXML: Fix a bug that unexpected methods can be called as a XPath function

	[HackerOne:249295]

	Reported by Andrea Jegher. Thanks!!!


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_4@59782 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nagachika 2017-09-08 14:25:52 +00:00
parent 5013a509cd
commit 05bc6eb40a
3 changed files with 43 additions and 7 deletions

View file

@ -8,10 +8,28 @@ module REXML
# Therefore, in XML, "local-name()" is identical (and actually becomes)
# "local_name()"
module Functions
@@available_functions = {}
@@context = nil
@@namespace_context = {}
@@variables = {}
INTERNAL_METHODS = [
:namespace_context,
:namespace_context=,
:variables,
:variables=,
:context=,
:get_namespace,
:send,
]
class << self
def singleton_method_added(name)
unless INTERNAL_METHODS.include?(name)
@@available_functions[name] = true
end
end
end
def Functions::namespace_context=(x) ; @@namespace_context=x ; end
def Functions::variables=(x) ; @@variables=x ; end
def Functions::namespace_context ; @@namespace_context ; end
@ -390,9 +408,14 @@ module REXML
node.node_type == :processing_instruction
end
def Functions::method_missing( id )
puts "METHOD MISSING #{id.id2name}"
XPath.match( @@context[:node], id.id2name )
def Functions::send(name, *args)
if @@available_functions[name.to_sym]
super
else
# TODO: Maybe, this is not XPath spec behavior.
# This behavior must be reconsidered.
XPath.match(@@context[:node], name.to_s)
end
end
end
end

View file

@ -221,5 +221,18 @@ module REXMLTests
m = REXML::XPath.match(doc, "//comment()[#{predicate}]")
assert_equal( [REXML::Comment.new("COMMENT A")], m )
end
def test_unregistered_method
doc = Document.new("<root/>")
assert_nil(XPath::first(doc.root, "to_s()"))
end
def test_nonexistent_function
doc = Document.new("<root><nonexistent/></root>")
# TODO: Maybe, this is not XPath spec behavior.
# This behavior must be reconsidered.
assert_equal(doc.root.elements[1],
XPath::first(doc.root, "nonexistent()"))
end
end
end

View file

@ -1,10 +1,10 @@
#define RUBY_VERSION "2.4.2"
#define RUBY_RELEASE_DATE "2017-08-05"
#define RUBY_PATCHLEVEL 181
#define RUBY_RELEASE_DATE "2017-09-08"
#define RUBY_PATCHLEVEL 182
#define RUBY_RELEASE_YEAR 2017
#define RUBY_RELEASE_MONTH 8
#define RUBY_RELEASE_DAY 5
#define RUBY_RELEASE_MONTH 9
#define RUBY_RELEASE_DAY 8
#include "ruby/version.h"