Skip to content

Commit 3d8b586

Browse files
committed
Fix regex for attribute selector |= and ~=
1 parent 6d1496a commit 3d8b586

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

src/helper.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -216,14 +216,16 @@ export const matchWithSelector = (element, selector) => {
216216
return attrValue.raw === unquoted;
217217
}
218218

219-
// TODO: Fix as it will match hyphen as well
220219
case "~=": {
221-
return new RegExp(`\\b${unquoted}\\b`).test(attrValue.raw)
220+
return new RegExp(`(?<=\\s)${unquoted}`).test(
221+
attrValue.raw
222+
) || unquoted === attrValue.raw
222223
}
223224

224-
// TODO: Fix as it will match hyphen as well
225225
case "|=": {
226-
return new RegExp(`\\b${unquoted}\\b`).test(attrValue.raw)
226+
return new RegExp(`(?<=-)${unquoted}`).test(
227+
attrValue.raw
228+
) || unquoted === attrValue.raw
227229
}
228230

229231
case "^=": {

0 commit comments

Comments
 (0)