Skip to content

Commit

Permalink
polling-jsonp: prevent client breakage with utf8 whitespace
Browse files Browse the repository at this point in the history
  • Loading branch information
rauchg committed Sep 10, 2012
1 parent 88e24fe commit 7eda4f0
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion lib/transports/polling-jsonp.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,14 @@ JSONP.prototype.onData = function (data) {
*/

JSONP.prototype.doWrite = function (data) {
data = this.head + JSON.stringify(data) + this.foot;
// we must output valid javascript, not valid json
// see: http://timelessrepo.com/json-isnt-a-javascript-subset
var js = JSON.stringify(data)
.replace(/\u2028/g, '\\u2028')
.replace(/\u2029/g, '\\u2029');

// prepare response
data = this.head + js + this.foot;

// explicit UTF-8 is required for pages not served under utf
var headers = {
Expand Down

0 comments on commit 7eda4f0

Please sign in to comment.