Skip to content

Context key scanner rejects the d and v regex flags in when clauses #332506

Description

Bug description

The context key expression scanner whitelists which regex flags may follow a regex literal in a when clause (src/vs/platform/contextkey/common/scanner.ts, _regexFlags). The set is

['i', 'g', 's', 'm', 'y', 'u']

which is missing the two newer ECMAScript flags: d (hasIndices) and v (unicodeSets). Both are valid in the engines VS Code ships on, but a when clause that uses them fails to lex: the trailing flag character is not consumed as part of the regex token, becomes a separate Str token, the parser then reports "Expected: REGEX", and ContextKeyExpr.deserialize returns undefined for a perfectly legal clause.

Example: an extension manifest containing

"when": "a =~ /x/d"

silently evaluates to never-match today.

Steps to reproduce

  1. Add a keybinding or view with "when": "editorTextFocus =~ /x/d" (any regex using the d or v flag).
  2. Observe the clause never activates; enabling context key tracing shows it deserialized to undefined.

Flags from the whitelist (/x/i, /x/gm) work as expected.

Expected behavior

All ECMAScript regex flags accepted by the runtime should lex, parse and deserialize, so /x/d and /x/v clauses behave like /x/i.

Version tested

Commit 77f86f3d3a0 on main. Reproduced at the unit level: scanning 'foo =~ /zee/d' yields a trailing Str 'd' token instead of a single RegexStr '/zee/d'. A fix plus scanner tests and an end-to-end deserialize test is ready.

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions