2022-11-10 10:43:16 +00:00
|
|
|
module.exports = {
|
|
|
|
meta: {
|
|
|
|
type: 'problem',
|
|
|
|
docs: {
|
|
|
|
description: 'disallow unescaped HTML literals',
|
|
|
|
url: require('../url')(module)
|
|
|
|
},
|
|
|
|
schema: []
|
|
|
|
},
|
2020-08-25 23:57:08 +00:00
|
|
|
|
2022-11-10 10:43:16 +00:00
|
|
|
create(context) {
|
|
|
|
const htmlOpenTag = /^<[a-zA-Z]/
|
|
|
|
const message = 'Unescaped HTML literal. Use html`` tag template literal for secure escaping.'
|
2020-08-25 23:57:08 +00:00
|
|
|
|
2022-11-10 10:43:16 +00:00
|
|
|
return {
|
|
|
|
Literal(node) {
|
|
|
|
if (!htmlOpenTag.test(node.value)) return
|
2020-08-25 23:57:08 +00:00
|
|
|
|
|
|
|
context.report({
|
|
|
|
node,
|
|
|
|
message
|
|
|
|
})
|
2022-11-10 10:43:16 +00:00
|
|
|
},
|
|
|
|
TemplateLiteral(node) {
|
|
|
|
if (!htmlOpenTag.test(node.quasis[0].value.raw)) return
|
|
|
|
|
|
|
|
if (!node.parent.tag || node.parent.tag.name !== 'html') {
|
|
|
|
context.report({
|
|
|
|
node,
|
|
|
|
message
|
|
|
|
})
|
|
|
|
}
|
2020-08-25 23:57:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|