Skip to content

Commit 487af10

Browse files
authored
fix(no-bare-strings-in-template): resolve regex matching order (#2682)
1 parent b1fa3b9 commit 487af10

File tree

2 files changed

+41
-2
lines changed

2 files changed

+41
-2
lines changed

Diff for: lib/rules/no-bare-strings-in-template.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,10 @@ module.exports = {
154154
const directives = opts.directives || DEFAULT_DIRECTIVES
155155

156156
const allowlistRe = new RegExp(
157-
allowlist.map((w) => regexp.escape(w)).join('|'),
157+
allowlist
158+
.map((w) => regexp.escape(w))
159+
.sort((a, b) => b.length - a.length)
160+
.join('|'),
158161
'gu'
159162
)
160163

Diff for: tests/lib/rules/no-bare-strings-in-template.js

+37-1
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,25 @@ tester.run('no-bare-strings-in-template', rule, {
114114
title="( ) , . & + - = * / # % ! ? : [ ] { } < > • — | &lpar; &rpar; &comma; &period; &amp; &AMP; &plus; &minus; &equals; &ast; &midast; &sol; &num; &percnt; &excl; &quest; &colon; &lsqb; &lbrack; &rsqb; &rbrack; &lcub; &lbrace; &rcub; &rbrace; &lt; &LT; &gt; &GT; &bull; &bullet; &mdash; &ndash; &nbsp; &Tab; &NewLine; &verbar; &vert; &VerticalLine;"
115115
/>
116116
</template>
117-
`
117+
`,
118+
{
119+
// https://github.com/vuejs/eslint-plugin-vue/issues/2681
120+
code: `
121+
<template>
122+
<h1> foo </h1>
123+
<h1> foo_bar </h1>
124+
</template>
125+
`,
126+
options: [{ allowlist: ['foo', 'foo_bar'] }]
127+
},
128+
{
129+
code: `
130+
<template>
131+
<h1>@@</h1>
132+
</template>
133+
`,
134+
options: [{ allowlist: ['@@'] }]
135+
}
118136
],
119137
invalid: [
120138
{
@@ -227,6 +245,24 @@ tester.run('no-bare-strings-in-template', rule, {
227245
}
228246
]
229247
},
248+
{
249+
code: `
250+
<template>
251+
<h1>foo</h1>
252+
<h1>foo_bar</h1>
253+
</template>
254+
`,
255+
options: [{ allowlist: ['foo'] }],
256+
errors: [
257+
{
258+
messageId: 'unexpected',
259+
line: 4,
260+
column: 13,
261+
endLine: 4,
262+
endColumn: 20
263+
}
264+
]
265+
},
230266
{
231267
code: `
232268
<template>

0 commit comments

Comments
 (0)