Fix extensions.allowed schema flagging valid version arrays as invalid - #329744
Open
RajeshKumar11 wants to merge 4 commits into
Open
Fix extensions.allowed schema flagging valid version arrays as invalid#329744RajeshKumar11 wants to merge 4 commits into
RajeshKumar11 wants to merge 4 commits into
Conversation
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
Contributor
There was a problem hiding this comment.
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. |
Contributor
Author
There was a problem hiding this comment.
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #327194.
The
extensions.allowedJSON schema declares twopatternPropertiesregexes: one matchingpublisher.extensionkeys (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.cpptoolsmatched both patterns — the publisher-only pattern matched by latching onto thecpptoolssuffix. 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 insettings.json, even though the setting still worked correctly at runtime.This likely went unnoticed until a recent
vscode-json-languageservicebump (#325505) started correctly enforcing validation against every matchingpatternPropertiespattern.Changes
^so they're mutually exclusive.EXTENSION_IDENTIFIER_PATTERNconstant, so it's reused directly instead of duplicating the regex inline.EXTENSION_PUBLISHER_IDENTIFIER_PATTERNas a named constant for the publisher-only pattern, mirroring the existing convention.Test plan
npm run typecheck-clientpassesextensionManagement.test.tsverifyingms-vscode.cpptoolsmatches only the extension-id pattern andms-vscodematches only the publisher pattern; ran via the Node test runner (extension identifier pattern and publisher identifier pattern are mutually exclusive (#327194)passes)["1.31.4"]would no longer be double-validated against the incompatible publisher-only schema