From 9134b09b873b49729ec78fe58774c4ddea0f2468 Mon Sep 17 00:00:00 2001 From: Michael Fellinger Date: Sun, 7 Jun 2009 16:34:35 +0900 Subject: [PATCH 1/4] Make mechanize_session_spec pass on 1.9 --- lib/webrat/mechanize.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 From 48a4ec905e4c6c2d3bd793d57222422598fad874 Mon Sep 17 00:00:00 2001 From: Michael Fellinger Date: Sun, 7 Jun 2009 16:45:19 +0900 Subject: [PATCH 2/4] Make sure Field#escaped_value also works when @value is an Array on 1.9 --- lib/webrat/core/elements/field.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/webrat/core/elements/field.rb b/lib/webrat/core/elements/field.rb index c887167..024d9ec 100644 --- a/lib/webrat/core/elements/field.rb +++ b/lib/webrat/core/elements/field.rb @@ -134,7 +134,7 @@ module Webrat end def escaped_value - CGI.escape(@value.to_s) + CGI.escape([*@value].first.to_s) end def labels From 520081c93eec6a01c740a148c91f5cf32e81aa0e Mon Sep 17 00:00:00 2001 From: Michael Fellinger Date: Sun, 7 Jun 2009 17:02:32 +0900 Subject: [PATCH 3/4] Don't use $LAST_MATCH_INFO since we don't require English.rb, use $~ instead --- lib/webrat/core/elements/link.rb | 2 +- lib/webrat/core/locators/link_locator.rb | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) 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..722aefc 100644 --- a/lib/webrat/core/locators/link_locator.rb +++ b/lib/webrat/core/locators/link_locator.rb @@ -45,7 +45,11 @@ module Webrat end def replace_nbsp(str) - str.gsub([0xA0].pack('U'), ' ') + if str.respond_to?(:force_encoding) + str.force_encoding('UTF-8').gsub(/\xc2\xa0/u, ' ') + else + str.gsub("\xc2\xa0", ' ') + end end def replace_nbsp_ref(str) From 8d2c027089f4d1ddc07a1e19d1ccf06c356a5f11 Mon Sep 17 00:00:00 2001 From: Michael Fellinger Date: Sun, 7 Jun 2009 17:03:13 +0900 Subject: [PATCH 4/4] Fix replacing of  , aka   so it works on 1.9 --- lib/webrat/core/locators/link_locator.rb | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/lib/webrat/core/locators/link_locator.rb b/lib/webrat/core/locators/link_locator.rb index 722aefc..a2e92a2 100644 --- a/lib/webrat/core/locators/link_locator.rb +++ b/lib/webrat/core/locators/link_locator.rb @@ -45,10 +45,14 @@ module Webrat end def replace_nbsp(str) - if str.respond_to?(:force_encoding) - str.force_encoding('UTF-8').gsub(/\xc2\xa0/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", ' ') + str.gsub(/\xc2\xa0/u, ' ') end end