Skip to content

Commit b8d44c0

Browse files
committed
Merge pull request #129 from shirish87/jshint-fixes
jshint Fixes
2 parents 151674d + 4b334b5 commit b8d44c0

File tree

5 files changed

+30
-11
lines changed

5 files changed

+30
-11
lines changed

.jshintrc

+5-1
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,9 @@
1212
"sub": true,
1313
"trailing": true,
1414
"undef": true,
15-
"unused": true
15+
"unused": true,
16+
"predef": [
17+
"require",
18+
"global"
19+
]
1620
}

bin/cli.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ function attachWorkerHelpers(worker) {
233233

234234
// worker has not acknowledged itself in 60 sec, reopen url
235235
client.changeUrl(self.id, { url: self.buildUrl() }, function () {
236-
logger.debug("[%s] Sent Request to reload url", self.getTestBrowserInfo());
236+
logger.debug('[%s] Sent Request to reload url', self.getTestBrowserInfo());
237237
});
238238

239239
}, ackTimeout * 1000);

lib/proxy.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ var http = require('http'),
44
var ProxyServer = {
55
onRequest: function(client_req, client_res, host, callback) {
66
var proxyUrl = url.parse(host);
7-
var path = url.parse(host);
87
var options = {
98
path: client_req.url,
109
hostname: proxyUrl.hostname,
@@ -14,7 +13,7 @@ var ProxyServer = {
1413
};
1514

1615
var proxy = http.request(options, function (res) {
17-
data = "";
16+
var data = '';
1817
res.on('data', function(chunk) {
1918
data += chunk;
2019
});

lib/utils.js

+7-3
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,13 @@ var Log = require('./logger'),
77

88
String.prototype.escapeSpecialChars = function() {
99
return this.replace(/\n/g, '\\n')
10-
// TODO what is this supposed to do? JSHint considers this "Bad or unnecessary escaping."
11-
.replace(/\\s/g, '\s')
12-
.replace(/\\\'/, '\'');
10+
.replace(/\r/g, '\\r')
11+
.replace(/\t/g, '\\t')
12+
.replace(/\f/g, '\\f')
13+
.replace(/\u0008/g, '\\u0008') // \b
14+
.replace(/\v/g, '\\u000b') // \v
15+
.replace(/\0/g, '\\u0000') // \0
16+
.replace(/\\\'/, '\''); // TODO: check why this exists
1317
};
1418

1519
var titleCase = function toTitleCase(str) {

tests/unit/utils_spec.js

+16-4
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ describe('Utilities', function(){
66
assert.equal("Hello", utils.titleCase("hello"));
77
assert.equal("Are You Serious?", utils.titleCase("are you serious?"));
88
});
9-
9+
1010
it('should generate 32 char uuid', function(){
1111
assert.equal(5, utils.uuid().split("-").length);
1212
assert.equal(32 + 4, utils.uuid().length);
@@ -16,24 +16,36 @@ describe('Utilities', function(){
1616
assert.notEqual(utils.uuid(), utils.uuid());
1717
assert.notEqual(utils.uuid(), utils.uuid());
1818
});
19-
19+
2020
it('should generate proper browser string for config', function(){
2121
var chrome_mac = {os: "OS X", os_version: "Mavericks", "browser": "chrome", "browser_version": "latest"};
2222
var chrome_windows = {os: "Windows", os_version: "XP", "browser": "chrome", "browser_version": "latest"};
2323
// var safari_mac = {os: "OS X", os_version: "Mountain Lion", "browser": "safari", "browser_version": "6.1"};
2424
var ie_windows = {os: "Windows", os_version: "7", "browser": "ie", "browser_version": "9.0"};
2525
var iOS = {os: "iOS", os_version: "6.0", device: "iPhone 5"};
2626
var androidConfig = {os: "android", os_version: "4.1"};
27-
27+
2828
assert.equal("OS X Mavericks, Chrome latest", utils.browserString(chrome_mac));
2929
assert.equal("Windows XP, Chrome latest", utils.browserString(chrome_windows));
3030
assert.equal("Windows 7, Internet Explorer 9.0", utils.browserString(ie_windows));
3131
assert.equal("iOS 6.0, iPhone 5", utils.browserString(iOS));
3232
assert.equal("android 4.1", utils.browserString(androidConfig));
3333
});
34-
34+
3535
it('should return number of keys for this object', function(){
3636
assert.equal(0, utils.objectSize({}));
3737
assert.equal(1, utils.objectSize({a: 2}));
3838
});
39+
40+
it('should escape special characters incompatible with JSON.parse', function () {
41+
var testString = '{"tracebacks":[{"actual":null,"message":"Died on test #1 at http://localhost:8888/test/main/globals.js:43:7\n at http://localhost:8888/test/main/globals.js:67:2: Error","testName":"globals: Exported assertions"}]}';
42+
var expectString = '{"tracebacks":[{"actual":null,"message":"Died on test #1 at http://localhost:8888/test/main/globals.js:43:7\\n at http://localhost:8888/test/main/globals.js:67:2: Error","testName":"globals: Exported assertions"}]}';
43+
44+
var malformedJson = '{ "key" : "Bad\njson contains\rall\tsorts\bof\vhorrible\0 & nasty\fescape sequences" }';
45+
var expectJson = { "key" : "Bad\njson contains\rall\tsorts\bof\u000bhorrible\u0000 & nasty\fescape sequences" };
46+
47+
assert.throws(function () { JSON.parse(testString); }, SyntaxError, 'JSON.parse fails');
48+
assert.equal(testString.escapeSpecialChars(), expectString);
49+
assert.equal(JSON.parse(malformedJson.escapeSpecialChars()).key, expectJson.key);
50+
});
3951
});

0 commit comments

Comments
 (0)