Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/plist.ts
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ function _parse(content: string, filename: string | null, locationKeyName: strin
function escapeVal(str: string): string {
return str.replace(/&#([0-9]+);/g, function (_: string, m0: string) {
return (<any>String).fromCodePoint(parseInt(m0, 10));
}).replace(/&#x([0-9a-f]+);/g, function (_: string, m0: string) {
}).replace(/&#x([0-9a-fA-F]+);/g, function (_: string, m0: string) {
return (<any>String).fromCodePoint(parseInt(m0, 16));
}).replace(/&amp;|&lt;|&gt;|&quot;|&apos;/g, function (_: string) {
switch (_) {
Expand Down
22 changes: 21 additions & 1 deletion src/tests/grammar.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import { test } from 'vitest';
import * as assert from 'assert';
import { EncodedTokenAttributes, OptionalStandardTokenType, StandardTokenType } from '../encodedTokenAttributes';
import { Registry } from '../main';
import { Registry, parseRawGrammar } from '../main';
import { FontStyle } from '../theme';
import { getOniguruma } from './onigLibs';
import { FontInfo } from '../grammar/grammar';
Expand Down Expand Up @@ -195,4 +195,24 @@ test('Fonts are correctly set 2', async function () {
} finally {
registry.dispose();
}
});

test('Plist grammars decode hexadecimal character references with uppercase digits', async function () {
const registry = new Registry({ loadGrammar: async () => undefined, onigLib: getOniguruma() });
try {
// XML writers can encode the carriage return of a CRLF line ending as `&#xD;`
const rawGrammar = parseRawGrammar(`<plist><dict>
<key>scopeName</key><string>source.test</string>
<key>patterns</key><array><dict>
<key>match</key><string>(?x)\\d+&#xD;
\\b</string>
<key>name</key><string>constant.numeric.test</string>
</dict></array>
</dict></plist>`, 'test.tmLanguage');
const grammar = await registry.addGrammar(rawGrammar);
const result = grammar.tokenizeLine('42', null);
assert.deepStrictEqual(result.tokens, [{ startIndex: 0, endIndex: 2, scopes: ['source.test', 'constant.numeric.test'] }]);
} finally {
registry.dispose();
}
});