Skip to content

Commit

Permalink
fix(no-useless-mustaches): escape < in fixes (#2389)
Browse files Browse the repository at this point in the history
  • Loading branch information
DMartens committed Feb 18, 2024
1 parent 5227eed commit 33b67a4
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/rules/no-useless-mustaches.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,9 @@ module.exports = {
// It doesn't autofix because another rule like indent or eol space might remove spaces.
return null
}
const escaped = text.replace(/</g, '&lt;')

return fixer.replaceText(node, text.replace(/\\([\S\s])/g, '$1'))
return fixer.replaceText(node, escaped.replace(/\\([\S\s])/g, '$1'))
}
})
}
Expand Down
48 changes: 48 additions & 0 deletions tests/lib/rules/no-useless-mustaches.js
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,54 @@ tester.run('no-useless-mustaches', rule, {
'Unexpected mustache interpolation with a string literal value.'
]
},
{
code: `
<template>
{{ '&lt;' }}
{{ '&gt;' }}
{{ '&amp;' }}
{{ '&#8212;' }}
</template>
`,
output: `
<template>
&lt;
&gt;
&amp;
&#8212;
</template>
`,
errors: [
'Unexpected mustache interpolation with a string literal value.',
'Unexpected mustache interpolation with a string literal value.',
'Unexpected mustache interpolation with a string literal value.',
'Unexpected mustache interpolation with a string literal value.'
]
},
{
code: `
<template>
{{ '<' }}
{{ '<<' }}
{{ 'can be < anywhere' }}
{{ '<tag>' }}
</template>
`,
output: `
<template>
&lt;
&lt;&lt;
can be &lt; anywhere
&lt;tag>
</template>
`,
errors: [
'Unexpected mustache interpolation with a string literal value.',
'Unexpected mustache interpolation with a string literal value.',
'Unexpected mustache interpolation with a string literal value.',
'Unexpected mustache interpolation with a string literal value.'
]
},
{
code: `
<template>
Expand Down

0 comments on commit 33b67a4

Please sign in to comment.