Skip to content

Commit 1f60b92

Browse files
author
dan norwood
committed
fix improper character escaping.
this will switch express-state to use json2. pertinent lines in json2: https://github.com/douglascrockford/JSON-js/blob/master/json2.js#L351
1 parent 44d8a91 commit 1f60b92

File tree

3 files changed

+10
-1
lines changed

3 files changed

+10
-1
lines changed

lib/serialize.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
'use strict';
22

33
var util = require('util');
4+
var json2 = require('JSON2');
45

56
module.exports = serialize;
67

@@ -24,7 +25,7 @@ function serialize(obj) {
2425
// Creates a JSON string representation of the object and uses placeholders
2526
// for functions and regexps (identified by index) which are later
2627
// replaced.
27-
str = JSON.stringify(obj, function (key, value) {
28+
str = json2.stringify(obj, function (key, value) {
2829
if (typeof value === 'function') {
2930
return '@__FUNCTION_' + (functions.push(value) - 1) + '__@';
3031
}

package.json

+3
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@
4040
"peerDependencies": {
4141
"express": "3.x"
4242
},
43+
"dependencies": {
44+
"JSON2": "0.1.0"
45+
},
4346
"devDependencies": {
4447
"chai": "*",
4548
"express": "3.x",

test/unit/serialize.js

+5
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,11 @@ describe('serialize( obj )', function () {
5252
it('should deserialize a JSON string to a JSON object', function () {
5353
expect(JSON.parse(serialize(data))).to.deep.equal(data);
5454
});
55+
56+
it('should serialize weird whitespace characters correctly', function () {
57+
var ws = String.fromCharCode(8232);
58+
expect(eval(serialize(ws))).to.equal(ws);
59+
});
5560
});
5661

5762
describe('functions', function () {

0 commit comments

Comments
 (0)