diff --git a/lib/webrat/core/field.rb b/lib/webrat/core/field.rb index 107bd66..e5a366c 100644 --- a/lib/webrat/core/field.rb +++ b/lib/webrat/core/field.rb @@ -56,10 +56,9 @@ module Webrat def to_param return nil if disabled? - value = @value.to_s.gsub('&', '%26') param_parser.parse_query_parameters("#{name}=#{value}") end - + def set(value) @value = value end @@ -78,6 +77,10 @@ module Webrat @element["name"] end + def value + CGI.escape(@value.to_s) + end + def labels @labels ||= label_elements.map { |element| Label.new(self, element) } end diff --git a/spec/api/fills_in_spec.rb b/spec/api/fills_in_spec.rb index b13b2cf..99682f6 100644 --- a/spec/api/fills_in_spec.rb +++ b/spec/api/fills_in_spec.rb @@ -157,4 +157,17 @@ describe "fills_in" do @session.fills_in :email, :with => "foo@example.com" @session.clicks_button end + + it "should escape field values" do + @session.response_body = <<-EOS +
+ EOS + @session.should_receive(:post).with("/users", "user" => {"phone" => "+1 22 33"}) + @session.fills_in 'Phone', :with => "+1 22 33" + @session.clicks_button + end end