Skip to content
Permalink
Browse files
When serializing text, encode all line breaks as CRLF pairs per the a…
…pplication/x-www-form-urlencoded specification. Fixes #6876.
  • Loading branch information
dmethvin authored and csnover committed Dec 31, 2010
1 parent 7e2810f commit eed3803
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
@@ -107,9 +107,9 @@ jQuery.fn.extend({
null :
jQuery.isArray(val) ?
jQuery.map( val, function(val, i){
return {name: elem.name, value: val};
return {name: elem.name, value: val.replace(/\r?\n/g, "\r\n")};

This comment has been minimized.

Copy link
@temp01

temp01 Jan 3, 2011

Contributor

This only gets run for multiple selects - Is the replacement needed here? Also, perhaps the regex should be cached at top like all the other regex's used in ajax.js and (jquery core).

This comment has been minimized.

Copy link
@dmethvin

dmethvin Jan 9, 2011

Author Member

It's somewhat pathological, but yes it can happen if the select-multiple has a value attribute with newlines. I agree on the regex, I've moved it to its own variable.

}) :
{name: elem.name, value: val};
{name: elem.name, value: val.replace(/\r?\n/g, "\r\n")};
}).get();
}
});
@@ -650,20 +650,20 @@ test("serialize()", function() {
'Check input serialization as query string');

equals( jQuery('#testForm').serialize(),
'T3=%3F%0AZ&H1=x&H2=&PWD=&T1=&T2=YES&My+Name=me&S1=abc&S3=YES&S4=',
'T3=%3F%0D%0AZ&H1=x&H2=&PWD=&T1=&T2=YES&My+Name=me&S1=abc&S3=YES&S4=',
'Check form serialization as query string');

equals( jQuery('#testForm :input').serialize(),
'T3=%3F%0AZ&H1=x&H2=&PWD=&T1=&T2=YES&My+Name=me&S1=abc&S3=YES&S4=',
'T3=%3F%0D%0AZ&H1=x&H2=&PWD=&T1=&T2=YES&My+Name=me&S1=abc&S3=YES&S4=',
'Check input serialization as query string');

equals( jQuery('#form, #testForm').serialize(),
"action=Test&radio2=on&check=on&hidden=&foo%5Bbar%5D=&name=name&search=search&email=dave%40jquery.com&number=43&select1=&select2=3&select3=1&select3=2&select5=3&T3=%3F%0AZ&H1=x&H2=&PWD=&T1=&T2=YES&My+Name=me&S1=abc&S3=YES&S4=",
"action=Test&radio2=on&check=on&hidden=&foo%5Bbar%5D=&name=name&search=search&email=dave%40jquery.com&number=43&select1=&select2=3&select3=1&select3=2&select5=3&T3=%3F%0D%0AZ&H1=x&H2=&PWD=&T1=&T2=YES&My+Name=me&S1=abc&S3=YES&S4=",
'Multiple form serialization as query string');

/* Temporarily disabled. Opera 10 has problems with form serialization.
equals( jQuery('#form, #testForm :input').serialize(),
"action=Test&radio2=on&check=on&hidden=&foo%5Bbar%5D=&name=name&search=search&email=dave%40jquery.com&number=43&select1=&select2=3&select3=1&select3=2&T3=%3F%0AZ&H1=x&H2=&PWD=&T1=&T2=YES&My+Name=me&S1=abc&S3=YES&S4=",
"action=Test&radio2=on&check=on&hidden=&foo%5Bbar%5D=&name=name&search=search&email=dave%40jquery.com&number=43&select1=&select2=3&select3=1&select3=2&T3=%3F%0D%0AZ&H1=x&H2=&PWD=&T1=&T2=YES&My+Name=me&S1=abc&S3=YES&S4=",
'Mixed form/input serialization as query string');
*/
jQuery("#html5email, #html5number").remove();

0 comments on commit eed3803

Please sign in to comment.