Skip to content

Fix extensions.allowed schema flagging valid version arrays as invalid - #329744

Open
RajeshKumar11 wants to merge 4 commits into
microsoft:mainfrom
RajeshKumar11:fix/allowed-extensions-schema-pattern-overlap
Open

Fix extensions.allowed schema flagging valid version arrays as invalid#329744
RajeshKumar11 wants to merge 4 commits into
microsoft:mainfrom
RajeshKumar11:fix/allowed-extensions-schema-pattern-overlap

Conversation

@RajeshKumar11

Copy link
Copy Markdown
Contributor

Summary

Fixes #327194.

The extensions.allowed JSON schema declares two patternProperties regexes: one matching publisher.extension keys (allows boolean/string/array-of-versions), and one matching publisher-only keys (allows boolean/string only). Both were anchored only at the end ($), not the start.

Because neither pattern was anchored at the start, a key like ms-vscode.cpptools matched both patterns — the publisher-only pattern matched by latching onto the cpptools suffix. JSON Schema requires a value to be valid against every pattern it matches, so an array value like ["1.31.4"] (valid under the extension-id pattern) failed validation against the publisher-only pattern, producing a false "Incorrect type. Expected one of boolean, string." warning in settings.json, even though the setting still worked correctly at runtime.

This likely went unnoticed until a recent vscode-json-languageservice bump (#325505) started correctly enforcing validation against every matching patternProperties pattern.

Changes

  • Anchor both patterns with ^ so they're mutually exclusive.
  • The extension-id pattern, once anchored, is identical to the existing EXTENSION_IDENTIFIER_PATTERN constant, so it's reused directly instead of duplicating the regex inline.
  • Added EXTENSION_PUBLISHER_IDENTIFIER_PATTERN as a named constant for the publisher-only pattern, mirroring the existing convention.
  • Added a regression test asserting the two patterns are mutually exclusive for a compound key.

Test plan

  • npm run typecheck-client passes
  • Added unit test in extensionManagement.test.ts verifying ms-vscode.cpptools matches only the extension-id pattern and ms-vscode matches only the publisher pattern; ran via the Node test runner (extension identifier pattern and publisher identifier pattern are mutually exclusive (#327194) passes)
  • Manually verified via regex simulation that ["1.31.4"] would no longer be double-validated against the incompatible publisher-only schema

The `extensions.allowed` JSON schema had two patternProperties regexes
anchored only at the end ($), not the start. This let a key like
`ms-vscode.cpptools` match both the extension-id pattern and the
publisher-only pattern (by matching just the `cpptools` suffix against
the latter). Since JSON Schema requires a value to satisfy every
matching pattern, an array value like ["1.31.4"] - valid under the
extension-id pattern - failed against the publisher-only pattern
(which only allows boolean/string), producing a false "Incorrect
type" warning in settings.json.

Anchor both patterns with ^ so they're mutually exclusive, and reuse
the now-identical EXTENSION_IDENTIFIER_PATTERN constant instead of
duplicating it inline.

Fixes microsoft#327194
Copilot AI balanced review requested due to automatic review settings August 8, 2026 04:51

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.

Pull request overview

Fixes false validation warnings for version arrays in extensions.allowed.

Changes:

  • Anchors extension and publisher schema patterns.
  • Reuses named regex constants.
  • Adds regression coverage for mutual exclusivity.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
extensionManagement.ts Corrects schema regex matching.
extensionManagement.test.ts Tests mutually exclusive patterns.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment on lines +36 to +40
// A key like `ms-vscode.cpptools` must match exactly one of the two
// `extensions.allowed` patternProperties patterns, otherwise the JSON
// schema validator requires the value to satisfy both patterns' schemas,
// incorrectly rejecting an array value (e.g. `["1.31.4"]`) that's only
// valid under the extension identifier pattern.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed in 4e7827f — condensed to one line.

Per review feedback: inline comments in method bodies should be a
single line explaining the non-obvious constraint, not a paragraph.
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.

Settings.json incorrectly marks permitted extension versions as not accepted

3 participants