-
-
Notifications
You must be signed in to change notification settings - Fork 385
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
64 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,7 @@ | |
"browser": true, | ||
"wsh": true, | ||
"-W099": true, | ||
"-W100": true, | ||
|
||
"predef": [ | ||
"HTMLHint", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/** | ||
* Copyright (c) 2014, Yanis Wang <[email protected]> | ||
* MIT Licensed | ||
*/ | ||
HTMLHint.addRule({ | ||
id: 'attr-unsafe-chars', | ||
description: 'Attribute value cant not use unsafe chars.', | ||
init: function(parser, reporter){ | ||
var self = this; | ||
parser.addListener('tagstart', function(event){ | ||
var attrs = event.attrs, | ||
attr, | ||
col = event.col + event.tagName.length + 1; | ||
var regUnsafe = /[\u0000-\u001f\u007f-\u009f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/; | ||
for(var i=0, l=attrs.length;i<l;i++){ | ||
attr = attrs[i]; | ||
if(regUnsafe.test(attr.value) === true){ | ||
reporter.warn('The value of attribute [ '+attr.name+' ] cant not use unsafe chars.', event.line, col + attr.index, self, attr.raw); | ||
} | ||
} | ||
}); | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/** | ||
* Copyright (c) 2013, Yanis Wang <[email protected]> | ||
* MIT Licensed | ||
*/ | ||
|
||
var expect = require("expect.js"); | ||
|
||
var HTMLHint = require("../../index").HTMLHint; | ||
|
||
var ruldId = 'attr-unsafe-chars', | ||
ruleOptions = {}; | ||
|
||
ruleOptions[ruldId] = true; | ||
|
||
describe('Rules: '+ruldId, function(){ | ||
|
||
it('Attribute value have unsafe chars should result in an error', function(){ | ||
var code = '<a href="https://vimeo.com/album/1951235/video/56931059">Sud Web 2012</a>'; | ||
var messages = HTMLHint.verify(code, ruleOptions); | ||
expect(messages.length).to.be(1); | ||
expect(messages[0].rule.id).to.be(ruldId); | ||
expect(messages[0].line).to.be(1); | ||
expect(messages[0].col).to.be(3); | ||
expect(messages[0].type).to.be('warning'); | ||
}); | ||
|
||
it('Attribute value have no unsafe chars should not result in an error', function(){ | ||
var code = '<input disabled="disabled" />'; | ||
var messages = HTMLHint.verify(code, ruleOptions); | ||
expect(messages.length).to.be(0); | ||
}); | ||
|
||
}); |