8000 Safe parse Circular JSON · browserstack/browserstack-runner@1825055 · GitHub
[go: up one dir, main page]

Skip to content

Commit 1825055

Browse files
committed
Safe parse Circular JSON
1 parent e5ede8b commit 1825055

File tree

3 files changed

+24
-12
lines changed

3 files changed

+24
-12
lines changed

lib/_patch/browserstack.js

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
}
1010

1111
// Tiny Ajax Post
12-
var post = function (url, json, cb){
12+
var post = function (url, json, cb) {
1313
var req;
1414

1515
if (window.ActiveXObject)
@@ -20,10 +20,15 @@
2020
throw "Strider: No ajax"
2121

2222
req.onreadystatechange = function () {
23-
if (req.readyState==4)
24-
cb(req.responseText);
25-
};
26-
var data = JSON.stringify(json);
23+
if (req.readyState==4)
24+
cb(req.responseText);
25+
};
26+
var data;
27+
if(window.CircularJSON) {
28+
data = window.CircularJSON.stringify(json);
29+
} else {
30+
data = JSON.stringify(json);
31+
}
2732
req.open("POST", url, true);
2833
req.setRequestHeader('X-Requested-With', 'XMLHttpRequest');
2934
req.setRequestHeader('X-Browser-String', BrowserStack.browser_string);

lib/server.js

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ var Log = require('./logger'),
1111
chalk = require('chalk'),
1212
mime = require('mime'),
1313
send = require('send'),
14-
vm = require('vm');
14+
vm = require('vm'),
15+
CircularJSON = require('circular-json');
1516

1617
exports.Server = function Server(bsClient, workers, config, callback) {
1718
var testFilePaths = (Array.isArray(config.test_path) ? config.test_path : [ config.test_path ])
@@ -64,6 +65,10 @@ exports.Server = function Server(bsClient, workers, config, callback) {
6465
var jsReportersScript = fs.readFileSync(jsReportersPath, {
6566
encoding: 'utf8'
6667
});
68+
var circularJSONPath = path.join(__dirname, '../node_modules/circular-json/build/circular-json.js');
69+
var circularJSONScript = fs.readFileSync(circularJSONPath, {
70+
encoding: 'utf8'
71+
});
6772

6873
if (pathMatches) {
6974
var framework = config['test_framework'];
@@ -75,6 +80,7 @@ exports.Server = function Server(bsClient, workers, config, callback) {
7580
});
7681

7782
patch += '<script type="text/javascript">' + jsReportersScript + '</script>';
83+
patch += '<script type="text/javascript">' + circularJSONScript + '</script>';
7884

7985
// adding framework scripts
8086
if (framework === 'jasmine') {
@@ -238,13 +244,13 @@ exports.Server = function Server(bsClient, workers, config, callback) {
238244
var query = null;
239245

240246
try {
241-
query = JSON.parse(body);
247+
query = CircularJSON.parse(body);
242248
} catch(e) {
243249
logger.info('[%s] Exception in parsing log', worker.string);
244250
logger.info('[%s] Log: ' + qs.parse(body).data, worker.string);
245251
}
246252

247-
logger.trace('[%s] _progress', worker.id, JSON.stringify(query));
253+
logger.trace('[%s] _progress', worker.id, CircularJSON.stringify(query));
248254

249255
if (query && query.test && query.test.errors) {
250256
var browserReport = getBrowserReport(browserInfo);
@@ -275,10 +281,10 @@ exports.Server = function Server(bsClient, workers, config, callback) {
275281

276282
var query = null;
277283
try {
278-
query = JSON.parse(body);
284+
query = CircularJSON.parse(body);
279285
} catch (e) {}
280286

281-
logger.trace('[%s] _report', worker.id, JSON.stringify(query));
287+
logger.trace('[%s] _report', worker.id, CircularJSON.stringify(query));
282288

283289
if (query === null) {
284290
logger.info('[%s] Null response from remote Browser', request.headers['x-browser-string']);

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,16 @@
1010
"dependencies": {
1111
"browserstack": "1.3.0",
1212
"chalk": "0.4.0",
13-
"js-reporters": "^1.1.0",
13+
"circular-json": "0.3.1",
14+
"js-reporters": "1.1.0",
1415
"mime": "1.3.4",
1516
"send": "0.13.0",
1617
"tunnel": "0.0.3"
1718
},
1819
"devDependencies": {
1920
"jshint": "2.5.6",
2021
"mocha": "1.15.1",
21-
"sinon": "^1.17.5"
22+
"sinon": "1.17.5"
2223
},
2324
"licenses": [
2425
{

0 commit comments

Comments
 (0)
0