Skip to content

Commit

Permalink
Merge pull request #300 from pyhrus/fix_jsonp_newline_escape
Browse files Browse the repository at this point in the history
JSONP transport fails when sending JSON stringified message
  • Loading branch information
rauchg committed May 13, 2014
2 parents a0aabca + 049b290 commit edb4c55
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/transports/polling-jsonp.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ module.exports = JSONPPolling;
*/

var rNewline = /\n/g;
var rEscapedNewline = /\\n/g;

/**
* Global JSONP callbacks.
Expand Down Expand Up @@ -211,6 +212,8 @@ JSONPPolling.prototype.doWrite = function (data, fn) {
initIframe();

// escape \n to prevent it from being converted into \r\n by some UAs
// double escaping is required for escaped new lines because unescaping of new lines can be done safely on server-side
data = data.replace(rEscapedNewline, '\\\n');
this.area.value = data.replace(rNewline, '\\n');

try {
Expand Down

0 comments on commit edb4c55

Please sign in to comment.