Permalink
Browse files

Replacing '%20' with '+' in for the keys too in the form to string se…

…rializer.
  • Loading branch information...
1 parent e6c89d2 commit a03039d23f3dbe8f12521dedecd1a56002bbcff5 Jorgen Rydenius committed Sep 21, 2012
Showing with 5 additions and 5 deletions.
  1. +3 −3 src/prototype/dom/form.js
  2. +1 −1 test/unit/fixtures/form.html
  3. +1 −1 test/unit/form_test.js
@@ -122,14 +122,14 @@ var Form = {
accumulator = function(result, key, values) {
if (!Object.isArray(values)) {values = [values];}
if (!values.length) {return result;}
- var encodedKey = encodeURIComponent(key);
+ // According to the spec, spaces should be '+' rather than '%20'.
+ var encodedKey = encodeURIComponent(key).gsub(/%20/, '+');
return result + (result ? "&" : "") + values.map(function (value) {
// Normalize newlines as \r\n because the HTML spec says newlines should
// be encoded as CRLFs.
value = value.gsub(/(\r)?\n/, '\r\n');
value = encodeURIComponent(value);
- // Likewise, according to the spec, spaces should be '+' rather than
- // '%20'.
+ // According to the spec, spaces should be '+' rather than '%20'.
value = value.gsub(/%20/, '+');
return encodedKey + "=" + value;
}).join("&");
@@ -118,7 +118,7 @@
</form>
<form id="form_with_inputs_needing_encoding" style="display:none">
- <input type="hidden" name="user[wristbands][][nickname]" id="fine_1" value="Hässlich" />
+ <input type="hidden" name="user[wristbands][ ][nickname]" id="fine_1" value="Hässlich" />
</form>
<form id="form_with_troublesome_input_names">
View
@@ -301,7 +301,7 @@ new Test.Unit.Runner({
},
testFormSerializeURIEncodesInputs: function() {
- this.assertEqual("user%5Bwristbands%5D%5B%5D%5Bnickname%5D=H%C3%A4sslich", $('form_with_inputs_needing_encoding').serialize(false));
+ this.assertEqual("user%5Bwristbands%5D%5B+%5D%5Bnickname%5D=H%C3%A4sslich", $('form_with_inputs_needing_encoding').serialize(false));
},
testFormMethodsOnExtendedElements: function() {

0 comments on commit a03039d

Please sign in to comment.