ruby-changes:47680
From: usa <ko1@a...>
Date: Sat, 9 Sep 2017 22:42:27 +0900 (JST)
Subject: [ruby-changes:47680] usa:r59796 (ruby_2_3): merge revision(s) 59584: [Backport #13850]
usa 2017-09-09 22:42:22 +0900 (Sat, 09 Sep 2017) New Revision: 59796 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=59796 Log: 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!!! Modified directories: branches/ruby_2_3/ Modified files: branches/ruby_2_3/lib/rexml/functions.rb branches/ruby_2_3/test/rexml/test_functions.rb branches/ruby_2_3/version.h Index: ruby_2_3/version.h =================================================================== --- ruby_2_3/version.h (revision 59795) +++ ruby_2_3/version.h (revision 59796) @@ -1,6 +1,6 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_3/version.h#L1 #define RUBY_VERSION "2.3.5" #define RUBY_RELEASE_DATE "2017-09-09" -#define RUBY_PATCHLEVEL 364 +#define RUBY_PATCHLEVEL 365 #define RUBY_RELEASE_YEAR 2017 #define RUBY_RELEASE_MONTH 9 Index: ruby_2_3/test/rexml/test_functions.rb =================================================================== --- ruby_2_3/test/rexml/test_functions.rb (revision 59795) +++ ruby_2_3/test/rexml/test_functions.rb (revision 59796) @@ -221,5 +221,18 @@ module REXMLTests https://github.com/ruby/ruby/blob/trunk/ruby_2_3/test/rexml/test_functions.rb#L221 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 Index: ruby_2_3/lib/rexml/functions.rb =================================================================== --- ruby_2_3/lib/rexml/functions.rb (revision 59795) +++ ruby_2_3/lib/rexml/functions.rb (revision 59796) @@ -8,10 +8,28 @@ module REXML https://github.com/ruby/ruby/blob/trunk/ruby_2_3/lib/rexml/functions.rb#L8 # 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 @@ -387,9 +405,14 @@ module REXML https://github.com/ruby/ruby/blob/trunk/ruby_2_3/lib/rexml/functions.rb#L405 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 Index: ruby_2_3 =================================================================== --- ruby_2_3 (revision 59795) +++ ruby_2_3 (revision 59796) Property changes on: ruby_2_3 ___________________________________________________________________ Modified: svn:mergeinfo ## -0,0 +0,1 ## Merged /trunk:r59584 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/