Skip to content

Commit

Permalink
Merge pull request #557 from GuillaumeGomez/fix-selectors
Browse files Browse the repository at this point in the history
Correctly handle selectors
  • Loading branch information
GuillaumeGomez authored Dec 24, 2023
2 parents a5b3699 + 4561f94 commit 0bfdb49
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ function getCssValue(value, text = '') {
if (css.error !== undefined) {
return css;
}
const index = css.value.search(/[A-Za-z\])]::[A-Za-z][A-Za-z0-9_]*$/);
const index = css.value.search(/[A-Za-z0-9\])-]::[A-Za-z][A-Za-z0-9_]*$/);
if (index !== -1) {
return {
'value': css.value.slice(0, index + 1),
Expand Down
12 changes: 12 additions & 0 deletions tests/html_files/change-page.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,24 @@
background-color: #fff;
text-decoration: none;
color: #111;
}
#before-1::after {
content: "a";
}
#before::after {
content: "b";
}
#before-::after {
content: "c";
}
</style>
</head>
<body>
<header>change page</header>
<button id="js-wait-nav" onclick="changePage()">hey</button>
<div id="before-1"></div>
<div id="before"></div>
<div id="before-"></div>
<script>
function changePage() {
setTimeout(() => {
Expand Down
11 changes: 11 additions & 0 deletions tests/ui-tests/pseudo-element-selection.goml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// Checks that pseudo element selection is working correctly (with one `:` and ending with an integer).
go-to: "file://" + |CURRENT_DIR| + "/" + |DOC_PATH| + "/change-page.html"
assert-css: ("#before-1::after", {"content": '"a"'})
// Should fail (not a pseudo element).
assert-css: ("#before-1:after", {"content": '"a"'})
assert-css: ("#before::after", {"content": '"b"'})
// Should fail (not a pseudo element).
assert-css: ("#before:after", {"content": '"b"'})
assert-css: ("#before-::after", {"content": '"c"'})
// Should fail (not a pseudo element).
assert-css: ("#before-:after", {"content": '"c"'})
9 changes: 9 additions & 0 deletions tests/ui-tests/pseudo-element-selection.output
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
=> Starting doc-ui tests...

pseudo-element-selection... FAILED
[ERROR] `tests/ui-tests/pseudo-element-selection.goml` line 5: "#before-1:after" not found: for command `assert-css: ("#before-1:after", {"content": '"a"'})`
[ERROR] `tests/ui-tests/pseudo-element-selection.goml` line 8: "#before:after" not found: for command `assert-css: ("#before:after", {"content": '"b"'})`
[ERROR] `tests/ui-tests/pseudo-element-selection.goml` line 11: "#before-:after" not found: for command `assert-css: ("#before-:after", {"content": '"c"'})`


<= doc-ui tests done: 0 succeeded, 1 failed

0 comments on commit 0bfdb49

Please sign in to comment.