Skip to content

Decode hexadecimal character references with uppercase digits in plist grammars - #316

Draft
Federico Brancasi (federicobrancasi) wants to merge 1 commit into
mainfrom
fbrancasi/plist-uppercase-hex-entities
Draft

Federico Brancasi (federicobrancasi) wants to merge 1 commit into
mainfrom
fbrancasi/plist-uppercase-hex-entities

Conversation

@federicobrancasi

Copy link
Copy Markdown
Member

A .tmLanguage (XML plist) grammar can contain a character reference with uppercase hex digits, like 
 (the carriage return of a CRLF line ending) or  . vscode-textmate keeps such a reference as the literal text 
 instead of the character. XML allows both cases (CharRef ::= '&#x' [0-9a-fA-F]+ ';'), and Python's plistlib, for example, decodes 
 to \r. A real grammar on GitHub, smuccione/slang LanguageServer/vscode/syntaxes/slang.tmGrammer.tmLanguage, has 61 of them in (?x) patterns such as:

<string>(?x)\b&#xD;
    (  (?i:&#xD;
          0x ( [0-9A-Fa-f]+ ( ' [0-9A-Fa-f]+ )* )?  # Hexadecimal&#xD;

In extended mode the leftover & becomes a literal that the pattern must match, and #xD; starts a comment. So the number rule never matches, and in x = 0x1F + 42; nothing gets constant.numeric.c. This happens because escapeVal in src/plist.ts decodes hex references with /&#x([0-9a-f]+);/g, which only accepts lowercase digits.

This PR accepts uppercase hex digits in that regex.

How to test

Command Result
npx vitest run 268 passed, 1 skipped; the new test "Plist grammars decode hexadecimal character references with uppercase digits" fails without the change
npx tsc passes

…t grammars

A `.tmLanguage` (XML plist) grammar can contain a character reference with uppercase hex digits, like `&#xD;` (the carriage return of a CRLF line ending) or `&#xA0;`. vscode-textmate keeps such a reference as the literal text `&#xD;` instead of the character. XML allows both cases (`CharRef ::= '&#x' [0-9a-fA-F]+ ';'`), and Python's `plistlib`, for example, decodes `&#xD;` to `\r`. A real grammar on GitHub, `smuccione/slang` `LanguageServer/vscode/syntaxes/slang.tmGrammer.tmLanguage`, has 61 of them in `(?x)` patterns such as:

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

There are no active review issues for the uppercase hexadecimal character-reference parsing fix.

No open issues 🎉

What changed in this PR

Fixes XML plist grammar parsing so hexadecimal character references with uppercase digits decode correctly, allowing affected grammar patterns to match as intended.

Changes:

  • Accepts A–F alongside lowercase hexadecimal digits in character references.
  • Adds a regression test verifying that a grammar containing &#xD; correctly tokenizes a number.
File Description
src/​tests/​grammar.test.ts Adds an end-to-end tokenization test for uppercase hexadecimal references.
src/​plist.ts Expands the hexadecimal reference regex to accept uppercase digits.

Review effort: Balanced

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants