Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #173 from scarpenter/script-url

Added "scripturl" option to allow ignoring things that look like javascript URLs.
  • Loading branch information...
commit bf8f97669458ff1f5bb8c919945d71d471c0a1d4 2 parents 2dfcf26 + f918cbc
@valueof valueof authored
Showing with 38 additions and 3 deletions.
  1. +4 −3 jshint.js
  2. +8 −0 tests/fixtures/scripturl.js
  3. +26 −0 tests/options.js
View
7 jshint.js
@@ -202,7 +202,7 @@
prototype, prototypejs, push, quit, range, raw, reach, reason, regexp,
readFile, readUrl, regexdash, removeEventListener, replace, report, require,
reserved, resizeBy, resizeTo, resolvePath, resumeUpdates, respond, rhino, right,
- runCommand, scroll, screen, scrollBy, scrollTo, scrollbar, search, seal, send,
+ runCommand, scroll, screen, scripturl, scrollBy, scrollTo, scrollbar, search, seal, send,
serialize, setInterval, setTimeout, shift, slice, sort,spawn, split, stack,
status, start, strict, sub, substr, supernew, shadow, supplant, sum, sync,
test, toLowerCase, toString, toUpperCase, toint32, token, top, trailing, type,
@@ -276,6 +276,7 @@ var JSHINT = (function () {
regexp : true, // if the . should not be allowed in regexp literals
rhino : true, // if the Rhino environment globals should be predefined
undef : true, // if variables should be declared before used
+ scripturl : true, // if script-targeted URLs should be tolerated
shadow : true, // if variable shadowing should be tolerated
strict : true, // require the "use strict"; pragma
sub : true, // if all forms of subscript notation are tolerated
@@ -894,7 +895,7 @@ var JSHINT = (function () {
}
t = Object.create(t);
if (type === '(string)' || type === '(range)') {
- if (jx.test(value)) {
+ if (!option.scripturl && jx.test(value)) {
warningAt("Script URL.", line, from);
}
}
@@ -2535,7 +2536,7 @@ loop: for (;;) {
if (left && right && left.id === '(string)' && right.id === '(string)') {
left.value += right.value;
left.character = right.character;
- if (jx.test(left.value)) {
+ if (!option.scripturl && jx.test(left.value)) {
warning("JavaScript URL.", left);
}
return left;
View
8 tests/fixtures/scripturl.js
@@ -0,0 +1,8 @@
+function bar() {
+javascript: for(;;) {
+ if (1==2) {
+ break javascript;
+ }
+ break;
+ }
+}
View
26 tests/options.js
@@ -233,6 +233,32 @@ exports.undef = function () {
assert.eql(JSHINT.errors[1].reason, "'localUndef' is not defined.");
};
+/** Option `scripturl` allows the use of javascript-type URLs */
+exports.scripturl = function() {
+ var code = "var foo = { 'count': 12, 'href': 'javascript:' };",
+ src = fs.readFileSync(__dirname + '/fixtures/scripturl.js', 'utf8');
+
+ // Make sure there is an error
+ assert.ok(!JSHINT(code));
+ assert.eql(JSHINT.errors.length, 1);
+ assert.eql(JSHINT.errors[0].reason, 'Script URL.');
+
+ // Make sure the error goes away when javascript URLs are tolerated
+ assert.ok(JSHINT(code, { scripturl: true }));
+
+ // Make sure an error exists for labels that look like URLs
+ assert.ok(!JSHINT(src));
+ assert.eql(JSHINT.errors.length, 1);
+ assert.eql(JSHINT.errors[0].line, 2);
+ assert.eql(JSHINT.errors[0].reason, "Label 'javascript' looks like a javascript url.");
+
+ // Make sure the label error exists even if javascript URLs are tolerated
+ assert.ok(!JSHINT(src, { scripturl: true }));
+ assert.eql(JSHINT.errors.length, 1);
+ assert.eql(JSHINT.errors[0].line, 2);
+ assert.eql(JSHINT.errors[0].reason, "Label 'javascript' looks like a javascript url.");
+};
+
/**
* Option `forin` disallows the use of for in loops without hasOwnProperty.
*
Please sign in to comment.
Something went wrong with that request. Please try again.