Skip to content

Commit 42e14a1

Browse files
committed
Merge pull request #38 from browserstack/bug_fixes
Remove special chars
2 parents cb8ec37 + a04e31b commit 42e14a1

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

lib/server.js

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,16 +99,22 @@ exports.Server = function Server(bsClient, workers) {
9999
}
100100

101101
function parseBody(body) {
102-
return JSON.parse(qs.parse(body).data.replace(/\n/g, "\\n"));
102+
// TODO: Have better implementation
103+
return JSON.parse(qs.parse(body).data.escapeSpecialChars());
103104
}
104105

105106
handlers = {
106107
"_progress": function progressHandler(uri, body, request, response) {
107-
query = parseBody(body);
108-
109108
var uuid = request.headers['x-worker-uuid'];
110109
var worker = workers[uuid];
111-
//console.log("Tests run:", query.tests_run);
110+
query = "";
111+
try {
112+
query = parseBody(body);
113+
} catch(e) {
114+
console.log("[%s] Exception in parsing QUnit log", worker.string)
115+
console.log("[%s] Log: " + qs.parse(body).data, worker.string)
116+
}
117+
112118
if (query.tracebacks) {
113119
query.tracebacks.forEach(function (traceback) {
114120
console.log("[%s] Error:", worker.string, traceback);

lib/utils.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,12 @@ var http = require('http');
33
var url = require('url');
44
var querystring = require('querystring');
55

6+
String.prototype.escapeSpecialChars = function() {
7+
return this.replace(/\n/g, "\\n")
8+
.replace(/\\s/g, "\s")
9+
.replace(/\\\'/, "\'");
10+
};
11+
612
var titleCase = function toTitleCase(str) {
713
return str.replace(/\w\S*/g, function (txt) {
814
return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase();

0 commit comments

Comments
 (0)