Repository navigation
Stop stripping JSONC comments with a regex in the PowerShell workload - #118
Open
Laurent Zogaj (26zl) wants to merge 1 commit into
Open
Laurent Zogaj (26zl) wants to merge 1 commit into
Laurent Zogaj (26zl) wants to merge 1 commit into
Conversation
Read-VSCodeSettings removed /* */ blocks before ConvertFrom-Json. The
pattern also matches from the "/**" at the end of one glob key to the
"**/" at the start of the next, so a settings.json containing
"files.exclude": { "**/.venv/**": true, "**/node_modules/**": true }
was rewritten as "**/.venvnode_modules/**" and the second entry was lost.
pwsh 7's ConvertFrom-Json accepts // and /* */ comments and trailing
commas natively, so the pre-processing is unnecessary.
A file that holds only comments parses to $null, where the regex path
used to return an empty table; that case returns an empty table again.
Contributor
Author
Contributor
Author
|
@microsoft-github-policy-service agree |
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.
Hi! I really like this project. I had built something similar for myself before I found it, and it has become my standard routine for every freshly reset PC; it runs on two of my own machines now.
One thing has been in the way: the PowerShell workload's ScriptAnalyzer unit mangles my VS Code
settings.json, so I have been running that workload from a local copy with the unit removed.Read-VSCodeSettingsstrips block comments with[regex]::Replace($raw, '/\*[\s\S]*?\*/', '')beforeConvertFrom-Json. That pattern also matches from the/**at the end of one glob key to the**/at the start of the next, sois written back as
"**/.venvnode_modules/**": true. The second entry is lost and the first is mangled, silently.The fix drops the regex pre-processing. The unit runs under pwsh 7, whose
ConvertFrom-Jsonhandles//,/* */and trailing commas natively, and as far as I can tell it already needs PowerShell 6+ (-AsHashtable,$IsMacOS), so nothing gets narrower. One detail: a file that holds only comments parses to$null, where the regex path returned an empty table, so that case is mapped back to an empty table. Reproduced on Windows 11 Pro 25H2 (build 26200.9550) with pwsh 7.6.6 by callingRead-VSCodeSettingson a file with the sample above; after the change both keys survive, a comment-only or empty file gives an empty table, invalid JSON still errors, the unit's three scripts parse and the YAML parses. The signed copy underWorkloads/is left to the sign pipeline.I have a few more small findings (a couple in the new Uninstall code, mostly docs that no longer match the scripts) and will open them as separate PRs; happy to combine them if you would rather have fewer.
Thanks for having a look.