Skip to content
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion docs/rules/unescaped-html-literal.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

Constructing raw HTML with string literals is error prone and may lead to security issues.

Instead use [`lit-html`](https://github.com/Polymer/lit-html)'s `html` tagged template literal to safely construct HTML literal strings. Alternatively, you can use document builder APIs like `document.createElement`.
Instead use [`lit-html`](https://github.com/Polymer/lit-html)'s `html` tagged template literal to safely construct HTML literal strings. Alternatively, you can implement your own `html` tagged template literal function, or use document builder APIs like `document.createElement`.

👎 Examples of **incorrect** code for this rule:

Expand Down
2 changes: 1 addition & 1 deletion lib/rules/unescaped-html-literal.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export default {
},

create(context) {
const htmlOpenTag = /^<[a-zA-Z]/
const htmlOpenTag = /^\s*<[a-zA-Z]/

return {
Literal(node) {
Expand Down
10 changes: 10 additions & 0 deletions tests/unescaped-html-literal.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,16 @@ ruleTester.run('unescaped-html-literal', rule, {
},
],
},
{
code: "const helloHTML = ` \n\t<div>Hello ${name}!</div>`",
parserOptions: {ecmaVersion: 2017},
errors: [
{
message: 'Unescaped HTML literal. Use html`` tag template literal for secure escaping.',
type: 'TemplateLiteral',
},
],
},
{
code: 'const helloHTML = foo`<div>Hello ${name}!</div>`',
parserOptions: {ecmaVersion: 2017},
Expand Down