Skip to content

Commit

Permalink
fix: ignore _ in hex values (#5934)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jason3S committed Jul 19, 2024
1 parent 80a724d commit 351c588
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 13 deletions.
25 changes: 13 additions & 12 deletions packages/cspell-lib/src/lib/Settings/RegExpPatterns.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -293,18 +293,19 @@ describe('Validate InDocSettings', () => {
expect(r?.[0]).toEqual(expected);
});
test.each`
str | expected
${''} | ${undefined}
${'hello'} | ${undefined}
${'commit 0x60975ea j'} | ${'0x60975ea'}
${'only letters 0xfeed j'} | ${'0xfeed'}
${'commit 0xfeeeeed1 j'} | ${'0xfeeeeed1'}
${'small value 0xf'} | ${'0xf'}
${'trailing _ messes stuff up 0xf_ '} | ${undefined}
${'leading _ messes stuff up _0xf '} | ${undefined}
${'leading digit does not match 10xf '} | ${undefined}
${'leading letter does not match a0xf '} | ${undefined}
${'commit c00ffee 0x0baad j'} | ${'0x0baad'}
str | expected
${''} | ${undefined}
${'hello'} | ${undefined}
${'commit 0x60975ea j'} | ${'0x60975ea'}
${'only letters 0xfeed j'} | ${'0xfeed'}
${'commit 0xfeeeeed1 j'} | ${'0xfeeeeed1'}
${'small value 0xf'} | ${'0xf'}
${'trailing _ messes stuff up 0xf_ '} | ${'0xf_'}
${'trailing _ messes stuff up 0xbadc_0ffe '} | ${'0xbadc_0ffe'}
${'leading _ messes stuff up _0xf '} | ${undefined}
${'leading digit does not match 10xf '} | ${undefined}
${'leading letter does not match a0xf '} | ${undefined}
${'commit c00ffee 0x0baad j'} | ${'0x0baad'}
`('regExHexValue "$str" expect "$expected"', ({ str, expected }) => {
const r = str.match(RegPat.regExCStyleHexValue);
expect(r?.[0]).toEqual(expected);
Expand Down
2 changes: 1 addition & 1 deletion packages/cspell-lib/src/lib/Settings/RegExpPatterns.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export const regExMatchCommonHexFormats =
/(?:#[0-9a-f]{3,8})|(?:0x[0-9a-f]+)|(?:\\u[0-9a-f]{4})|(?:\\x\{[0-9a-f]{4}\})/gi;
export const regExCommitHash = /\b(?![a-f]+\b)(?:0x)?[0-9a-f]{7,}\b/gi; // Match Commit Hashes that contain at least one digit.
export const regExCommitHashLink = /\[[0-9a-f]{7,}\]/gi; // Match Commit Hash Markdown link: [abcdef0].
export const regExCStyleHexValue = /\b0x[0-9a-f]+\b/gi;
export const regExCStyleHexValue = /\b0x[0-9a-f_]+\b/gi;
export const regExCSSHexValue = /#[0-9a-f]{3,8}\b/gi;
export const regExUUID = /\b[0-9a-fx]{8}-[0-9a-fx]{4}-[0-9a-fx]{4}-[0-9a-fx]{4}-[0-9a-fx]{12}\b/gi; // x - represents placeholder values
export const regExUnicodeRef = /\bU\+[0-9a-f]{4,5}(?:-[0-9a-f]{4,5})?/gi;
Expand Down

0 comments on commit 351c588

Please sign in to comment.