Skip to content

Commit a03039d

Browse files
author
Jorgen Rydenius
committed
Replacing '%20' with '+' in for the keys too in the form to string serializer.
1 parent e6c89d2 commit a03039d

File tree

3 files changed

+5
-5
lines changed

3 files changed

+5
-5
lines changed

src/prototype/dom/form.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -122,14 +122,14 @@ var Form = {
122122
accumulator = function(result, key, values) {
123123
if (!Object.isArray(values)) {values = [values];}
124124
if (!values.length) {return result;}
125-
var encodedKey = encodeURIComponent(key);
125+
// According to the spec, spaces should be '+' rather than '%20'.
126+
var encodedKey = encodeURIComponent(key).gsub(/%20/, '+');
126127
return result + (result ? "&" : "") + values.map(function (value) {
127128
// Normalize newlines as \r\n because the HTML spec says newlines should
128129
// be encoded as CRLFs.
129130
value = value.gsub(/(\r)?\n/, '\r\n');
130131
value = encodeURIComponent(value);
131-
// Likewise, according to the spec, spaces should be '+' rather than
132-
// '%20'.
132+
// According to the spec, spaces should be '+' rather than '%20'.
133133
value = value.gsub(/%20/, '+');
134134
return encodedKey + "=" + value;
135135
}).join("&");

test/unit/fixtures/form.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@
118118
</form>
119119

120120
<form id="form_with_inputs_needing_encoding" style="display:none">
121-
<input type="hidden" name="user[wristbands][][nickname]" id="fine_1" value="Hässlich" />
121+
<input type="hidden" name="user[wristbands][ ][nickname]" id="fine_1" value="Hässlich" />
122122
</form>
123123

124124
<form id="form_with_troublesome_input_names">

test/unit/form_test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ new Test.Unit.Runner({
301301
},
302302

303303
testFormSerializeURIEncodesInputs: function() {
304-
this.assertEqual("user%5Bwristbands%5D%5B%5D%5Bnickname%5D=H%C3%A4sslich", $('form_with_inputs_needing_encoding').serialize(false));
304+
this.assertEqual("user%5Bwristbands%5D%5B+%5D%5Bnickname%5D=H%C3%A4sslich", $('form_with_inputs_needing_encoding').serialize(false));
305305
},
306306

307307
testFormMethodsOnExtendedElements: function() {

0 commit comments

Comments
 (0)