Skip to content

Commit

Permalink
fix: incorrect handling elemental selector without a namespace (#394)
Browse files Browse the repository at this point in the history
  • Loading branch information
Semigradsky authored Jan 11, 2021
1 parent a334fa3 commit 3215f5a
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 1 deletion.
28 changes: 28 additions & 0 deletions src/__fixtures__/tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -843,6 +843,19 @@ export const tests: [
],
"star tag namespace",
],
[
"|bar",
[
[
{
name: "bar",
type: "tag",
namespace: "",
},
],
],
"without namespace",
],
[
"*|*",
[
Expand Down Expand Up @@ -870,6 +883,21 @@ export const tests: [
],
"basic attribute namespace, existential",
],
[
"[|bar]",
[
[
{
action: "exists",
name: "bar",
type: "attribute",
namespace: "",
value: "",
},
],
],
"without namespace, existential",
],
[
"[foo|bar='baz' i]",
[
Expand Down
4 changes: 4 additions & 0 deletions src/parse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,10 @@ function parseSelector(
selectorIndex += 1;
name = "*";
} else if (reName.test(selector.slice(selectorIndex))) {
if (selector.charAt(selectorIndex) === "|") {
namespace = "";
selectorIndex += 1;
}
name = getName(0);
} else {
/*
Expand Down
2 changes: 1 addition & 1 deletion src/stringify.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ function getNamespacedName(token: {
}

function getNamespace(namespace: string | null): string {
return namespace
return namespace !== null
? `${namespace === "*" ? "*" : escapeName(namespace)}|`
: "";
}
Expand Down

0 comments on commit 3215f5a

Please sign in to comment.