Skip to content

Fixed error to not allow < within script tags, see bug https://github… #152

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 28 additions & 3 deletions lib/rules/disallow-html-text.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,33 @@ module.exports.prototype = {
},

lint: function (file, errors) {
file.addErrorForAllTokensByFilter(function (token) {
return token.type === 'text-html' || (token.type === 'text' && /<[^\n]*/.test(token.val));
}, errors, 'HTML text must not be used');
file.addErrorForAllTokensByFilter(
function (token) {
if (token.type === 'text-html') {
return true;
}

// allow within specific tags, therefor look up the parent tag
if (token.type === 'text' && /<[^\n]*/.test(token.val)) {
var previousToken = token;
do {
previousToken = file._tokens[previousToken._index - 1];
if (previousToken.type === 'tag') {
// add allowed tags here
if (['script'].indexOf(previousToken.val) !== -1) {
return false;
}
return true;
}
} while (previousToken);
}

return (
token.type === 'text-html' ||
(token.type === 'text' && /<[^\n]*/.test(token.val))
);
},
errors, 'HTML text must not be used'
);
}
};