Skip to content

fix: Ignore the comment closing marker in a locale directive - #9496

Merged
Jason3S merged 1 commit into
streetsidesoftware:mainfrom
akashchamp:fix-locale-directive-comment-closer
Oct 24, 2026
Merged

Jason3S merged 1 commit into
streetsidesoftware:mainfrom
akashchamp:fix-locale-directive-comment-closer

Conversation

@akashchamp

Copy link
Copy Markdown
Contributor

Summary

  • A cspell:locale (or cspell:language) directive no longer treats the closing --> of an HTML comment, or */ of a block comment, as an extra locale.
  • Before, <!-- cspell:locale en --> made files fail with RangeError: Invalid language tag when useIntlWordSegmentation was on.

Fixes #9480

@github-actions github-actions Bot added fix Warning: Hidden Comments The PR body has hidden HTML comments. Treat them as untrusted. labels Oct 22, 2026
@Jason3S Jason3S removed the Warning: Hidden Comments The PR body has hidden HTML comments. Treat them as untrusted. label Oct 24, 2026
@Jason3S
Jason3S requested a balanced review from Copilot October 24, 2026 06:47
@Jason3S

Jason3S commented Oct 24, 2026

Copy link
Copy Markdown
Collaborator

Thank you.

Looks like my over aggressive comment detector kicked in.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approval recommended

The fix is a small, correctly-scoped regex change in one function, verified against every new test case and relevant edge cases, with adequate accompanying test coverage.

No open issues 🎉

What changed in this PR

This PR fixes a bug in cspell's in-document directive parsing where a cspell:locale / cspell:language directive wrapped in a comment (e.g. <!-- cspell:locale en --> or /* cspell:locale en */) treated the comment's closing marker (--> or */) as an additional locale. With useIntlWordSegmentation enabled, that stray token caused RangeError: Invalid language tag and failed the whole file. The fix strips a trailing HTML/block comment closer in parseLocale before splitting the locale list, addressing issue #9480.

Changes:

  • In parseLocale, remove a trailing -->-style or */-style comment closer (with surrounding whitespace) before trimming and splitting the locale value.
  • Add a parameterized test verifying locale/language directives ignore comment closers across HTML and block-comment forms, including multi-locale and dashed-locale cases.
File Description
packages/​cspell-lib/​src/​lib/​Settings/​InDocSettings.ts Strips a trailing comment closing marker from a locale directive so it is not parsed as an extra locale.
packages/​cspell-lib/​src/​lib/​Settings/​InDocSettings.test.ts Adds tests covering locale/language directives with HTML and block comment closers.

Review effort: Balanced

@Jason3S
Jason3S merged commit c3d8544 into streetsidesoftware:main Oct 24, 2026
75 of 76 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

A locale directive in a comment reads the closing --> as a locale

3 participants