Skip to content

Commit

Permalink
fix(xml): handling of html entities with hex code that contains lette…
Browse files Browse the repository at this point in the history
…rs (#88)
  • Loading branch information
lowlighter authored Dec 4, 2024
1 parent ad75220 commit bbc1792
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion xml/parse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,7 @@ function revive(node: xml_node | xml_text, key: string, options: options) {
value = value.trim()
}
if (options?.revive?.entities) {
value = value.replaceAll(/&#(?<hex>x?)(?<code>\d+);/g, (_, hex, code) => String.fromCharCode(Number.parseInt(code, hex ? 16 : 10)))
value = value.replaceAll(/&#(?<hex>x?)(?<code>[A-Fa-f\d]+);/g, (_, hex, code) => String.fromCharCode(Number.parseInt(code, hex ? 16 : 10)))
for (const [entity, character] of Object.entries(entities)) {
value = value.replaceAll(entity, character)
}
Expand Down
4 changes: 2 additions & 2 deletions xml/parse_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -365,12 +365,12 @@ test("`parse()` xml syntax hexadecimal entity reference", () =>
expect(
parse(`
<root>
&#x26;
&#x26; &#xA9; &#xa9;
</root>
`),
).toEqual(
{
root: "&",
root: "& © ©",
},
))

Expand Down

0 comments on commit bbc1792

Please sign in to comment.