Skip to content

Commit b9eae3e

Browse files
committed
Make spec-char-escape more accurate
1 parent 2536cbf commit b9eae3e

File tree

3 files changed

+7
-6
lines changed

3 files changed

+7
-6
lines changed

lib/htmlhint.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/rules/spec-char-escape.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@ HTMLHint.addRule({
88
init: function(parser, reporter){
99
var self = this;
1010
parser.addListener('text', function(event){
11-
if(/[<>]/.test(event.raw) === true){
12-
reporter.error('Special characters must be escaped.', event.line, event.col, self, event.raw);
11+
var match = event.raw.match(/[<>]/);
12+
if(match !== null){
13+
reporter.error('Special characters must be escaped [ '+match[0]+' ].', event.line, event.col + match.index, self, event.raw);
1314
}
1415
});
1516
}

tests/test.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//本文件临时开发测试用,近期开始写完整的单测
22
var HTMLHint = require('../lib/htmlhint').HTMLHint;
3-
var text = '\r\n\r\na<!DOCTYPE html><html lanG="en" b=\'1\' c=2><heaD\r\na>a<\r\nb\r\nc<meta content="text/html; charset=utf-8" http-equiv="Content-Type" /><script></script></head><body class="classA b c d"><img src=""><br><ul id="abA"><li><span></ul></aaa><style>a{}</style>abc<script>var aaa;</script></body></html>';
3+
var text = '\r\n\r\na<!DOCTYPE html><html lanG="en" b=\'1\' c=2><heaD\r\na>ab<\r\nb\r\nc<meta content="text/html; charset=utf-8" http-equiv="Content-Type" /><script></script></head><body class="classA b c d"><img src=""><br><ul id="abA"><li><span></ul></aaa><style>a{}</style>abc<script>var aaa;</script></body></html>';
44
// text = '';
55
var messages = HTMLHint.verify(text, {
66
// 'img-alt-require': true,
@@ -11,9 +11,9 @@ var messages = HTMLHint.verify(text, {
1111
// 'attr-lower-case': true,
1212
// 'attr-value-double-quotes': true,
1313
// 'attr-value-empty': true,
14-
// 'spec-char-escape': true,
14+
'spec-char-escape': true,
1515
// 'style-disabled': true,
16-
'tag-pair': true,
16+
// 'tag-pair': true,
1717
// 'tag-self-close': true,
1818
// 'id-class-value': {
1919
// 'regId': /^(J-)?[a-z\d]+(-[a-z\d]+)*$/,

0 commit comments

Comments
 (0)