Bug fix for 1.7.1 regression in Form.serialize(true/false) #66

Merged
merged 3 commits into from Sep 27, 2012

Projects

None yet

4 participants

npup and others added some commits Sep 20, 2012
@npup npup Add test and changes for serializing forms with multiple select to a …
…string to work again.

Signed-off-by: Jorgen Rydenius <jorgen@pingpong.net>
24414bf
Jorgen Rydenius Fixed bug #1384 for the hash accumulator + test case. e6c89d2
@victor-homyakov victor-homyakov and 1 other commented on an outdated diff Sep 21, 2012
src/prototype/dom/form.js
- value = value.gsub(/%20/, '+');
- return result + (result ? '&' : '') + encodeURIComponent(key) + '=' + value;
- }
+ accumulator = function(result, key, values) {
+ if (!Object.isArray(values)) {values = [values];}
+ if (!values.length) {return result;}
+ var encodedKey = encodeURIComponent(key);
+ 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'.
+ value = value.gsub(/%20/, '+');
+ return encodedKey + "=" + value;
@victor-homyakov
victor-homyakov Sep 21, 2012

Please note that encodedKey also should have spaces replaced with +.

@rydenius
rydenius Sep 21, 2012

Thanks for the comment. I added a third commit to this pull request that fixes that problem too.

@savetheclocktower savetheclocktower merged commit d017062 into sstephenson:master Sep 27, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment