From 67ada1168e630ae9407975e8fa25c6aad15bff90 Mon Sep 17 00:00:00 2001 From: Yorick Peterse Date: Sun, 30 Aug 2015 02:10:49 +0200 Subject: [PATCH] Fix starts-with() for JRuby 1.7 ''.start_with?('') returns false on JRuby 1.7. While I'd love to drop support for shit like this, JRuby 1.7 is still in common use today, so lets just work around this for now. --- lib/oga/xpath/compiler.rb | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/lib/oga/xpath/compiler.rb b/lib/oga/xpath/compiler.rb index 512879a..0809651 100644 --- a/lib/oga/xpath/compiler.rb +++ b/lib/oga/xpath/compiler.rb @@ -1032,10 +1032,16 @@ module Oga needle_var.assign(try_match_first_node(needle, input)) end .followed_by do - converted = conversion.to_string(haystack_var) - .start_with?(conversion.to_string(needle_var)) + haystack_var.assign(conversion.to_string(haystack_var)) + .followed_by do + needle_var.assign(conversion.to_string(needle_var)) + end + .followed_by do + equal = needle_var.empty? + .or(haystack_var.start_with?(needle_var)) - block_given? ? converted.if_true { yield } : converted + block_given? ? equal.if_true { yield } : equal + end end end