From 846a90e561a086cee072dc0fc135e63197edbc58 Mon Sep 17 00:00:00 2001 From: Josh Lubaway Date: Fri, 29 May 2009 10:42:30 -0700 Subject: [PATCH] Passing TextField values as plaintext to Mechanize. Mechanize takes input as plaintext and escapes field values on its own. If the values are escaped before they are passed to Mechanize, the values will be escaped twice. These doubly-escaped values will result in incorrect behavior on the server side. --- lib/webrat/core/elements/field.rb | 2 ++ spec/private/core/field_spec.rb | 16 ++++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/lib/webrat/core/elements/field.rb b/lib/webrat/core/elements/field.rb index 7eecc94..c887167 100644 --- a/lib/webrat/core/elements/field.rb +++ b/lib/webrat/core/elements/field.rb @@ -87,6 +87,8 @@ module Webrat parse_rails_request_params("#{name}=#{escaped_value}") when :merb ::Merb::Parse.query("#{name}=#{escaped_value}") + when :mechanize + { name => value } else { name => escaped_value } end diff --git a/spec/private/core/field_spec.rb b/spec/private/core/field_spec.rb index 90b6227..1e7f199 100644 --- a/spec/private/core/field_spec.rb +++ b/spec/private/core/field_spec.rb @@ -66,4 +66,20 @@ module Webrat radio_button.should_not be_checked end end + + describe TextField do + it 'should not escape values in mechanize mode' do + Webrat.configuration.mode = :mechanize + + html = <<-HTML + + + + HTML + + element = Webrat::XML.css_search(Webrat::XML.document(html), 'input').first + text_field = TextField.new(nil, element) + text_field.to_param.should == { 'email' => 'user@example.com' } + end + end end