Skip to content

Commit 28596ce

Browse files
committed
fix: incorrect handling elemental selector without a namespace
1 parent a334fa3 commit 28596ce

File tree

3 files changed

+33
-1
lines changed

3 files changed

+33
-1
lines changed

src/__fixtures__/tests.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -843,6 +843,19 @@ export const tests: [
843843
],
844844
"star tag namespace",
845845
],
846+
[
847+
"|bar",
848+
[
849+
[
850+
{
851+
name: "bar",
852+
type: "tag",
853+
namespace: "",
854+
},
855+
],
856+
],
857+
"without namespace",
858+
],
846859
[
847860
"*|*",
848861
[
@@ -870,6 +883,21 @@ export const tests: [
870883
],
871884
"basic attribute namespace, existential",
872885
],
886+
[
887+
"[|bar]",
888+
[
889+
[
890+
{
891+
action: "exists",
892+
name: "bar",
893+
type: "attribute",
894+
namespace: "",
895+
value: "",
896+
},
897+
],
898+
],
899+
"without namespace, existential",
900+
],
873901
[
874902
"[foo|bar='baz' i]",
875903
[

src/parse.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -391,6 +391,10 @@ function parseSelector(
391391
selectorIndex += 1;
392392
name = "*";
393393
} else if (reName.test(selector.slice(selectorIndex))) {
394+
if (selector.charAt(selectorIndex) === "|") {
395+
namespace = "";
396+
selectorIndex += 1;
397+
}
394398
name = getName(0);
395399
} else {
396400
/*

src/stringify.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ function getNamespacedName(token: {
106106
}
107107

108108
function getNamespace(namespace: string | null): string {
109-
return namespace
109+
return namespace !== null
110110
? `${namespace === "*" ? "*" : escapeName(namespace)}|`
111111
: "";
112112
}

0 commit comments

Comments
 (0)