diff --git a/lib/webrat/core/elements/field.rb b/lib/webrat/core/elements/field.rb index 1a2088d..7900d88 100644 --- a/lib/webrat/core/elements/field.rb +++ b/lib/webrat/core/elements/field.rb @@ -134,8 +134,7 @@ module Webrat end def escaped_value - value = @value.respond_to?(:join) ? @value.join : @value - value ? CGI.escape(value) : "" + CGI.escape([*@value].first.to_s) end def labels diff --git a/lib/webrat/core/elements/link.rb b/lib/webrat/core/elements/link.rb index 5b83e36..0edf8d4 100644 --- a/lib/webrat/core/elements/link.rb +++ b/lib/webrat/core/elements/link.rb @@ -53,7 +53,7 @@ module Webrat def authenticity_token return unless onclick && onclick.include?("s.setAttribute('name', 'authenticity_token');") && onclick =~ /s\.setAttribute\('value', '([a-f0-9]{40})'\);/ - $LAST_MATCH_INFO.captures.first + $~.captures.first end def onclick diff --git a/lib/webrat/core/locators/link_locator.rb b/lib/webrat/core/locators/link_locator.rb index 426c527..a2e92a2 100644 --- a/lib/webrat/core/locators/link_locator.rb +++ b/lib/webrat/core/locators/link_locator.rb @@ -45,7 +45,15 @@ module Webrat end def replace_nbsp(str) - str.gsub([0xA0].pack('U'), ' ') + if str.respond_to?(:valid_encoding?) + if str.valid_encoding? + str.gsub(/\xc2\xa0/u, ' ') + else + str.force_encoding('UTF-8').gsub(/\xc2\xa0/u, ' ') + end + else + str.gsub(/\xc2\xa0/u, ' ') + end end def replace_nbsp_ref(str) diff --git a/lib/webrat/mechanize.rb b/lib/webrat/mechanize.rb index 1bdcb90..41296cf 100644 --- a/lib/webrat/mechanize.rb +++ b/lib/webrat/mechanize.rb @@ -67,7 +67,7 @@ module Webrat #:nodoc: else current_path.split("/")[0..(-1 - levels_up)].join("/") end - descendent = url.split("/")[levels_up..-1] + descendent = url.split("/")[levels_up..-1].join "#{ancestor}/#{descendent}" end end