Skip to content

Commit

Permalink
Don't traverse into script or style tags in the dom rule (fixes #221
Browse files Browse the repository at this point in the history
…and #257)
  • Loading branch information
mlochbaum committed Apr 22, 2019
1 parent 0d0d6f3 commit 36975ed
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
13 changes: 9 additions & 4 deletions lib/rules/dom.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,15 @@ module.exports.lint = function(dom, opts, inlineConfigs) {
var s = subs.filter(matcher);
var ret = knife.applyRules(s, element, inlineConfigs.current);

if (element.children && element.children.length > 0) {
element.children.forEach(function (child) {
ret = ret.concat(getIssues(child));
});
switch (element.type) {
case 'script': case 'style':
break;
default:
if (element.children && element.children.length > 0) {
element.children.forEach(function (child) {
ret = ret.concat(getIssues(child));
});
}
}
return ret;
};
Expand Down
5 changes: 5 additions & 0 deletions test/functional/spec-char-escape.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,10 @@ module.exports = [
input: 'AA&Bb aa&bb',
opts: { 'spec-char-escape': true, 'text-ignore-regex': /aa.*?bb/i },
output: 0
}, {
desc: 'should not apply to style or script tags',
input: '<style>.Tag>div{color:#fff}</style><script>function lt(a,b){return a<b;}</script>',
opts: { 'spec-char-escape': true },
output: 0
}
];

0 comments on commit 36975ed

Please sign in to comment.