Skip to content

handle errant whitespace in global.json#15086

Merged
brettfo merged 1 commit into
mainfrom
dev/brettfo/nuget-global-json-whitespace
May 20, 2026
Merged

handle errant whitespace in global.json#15086
brettfo merged 1 commit into
mainfrom
dev/brettfo/nuget-global-json-whitespace

Conversation

@brettfo
Copy link
Copy Markdown
Contributor

@brettfo brettfo commented May 20, 2026

The JSON parser in PowerShell doesn't like leading newline characters which makes handling global.json files difficult. This PR forces the file to be read as a single string with -Raw which enables ConvertFrom-Json to work.

@github-actions github-actions Bot added the L: dotnet:nuget NuGet packages via nuget or dotnet label May 20, 2026
@brettfo brettfo force-pushed the dev/brettfo/nuget-global-json-whitespace branch from 1a8e61b to ec4427e Compare May 20, 2026 18:31
@brettfo brettfo marked this pull request as ready for review May 20, 2026 18:47
@brettfo brettfo requested a review from a team as a code owner May 20, 2026 18:47
Copilot AI review requested due to automatic review settings May 20, 2026 18:47
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Updates the NuGet updater’s PowerShell logic for reading global.json so SDK version discovery is resilient to leading whitespace/newlines, and adds regression test scenarios to validate the behavior.

Changes:

  • Read global.json using Get-Content -Raw before ConvertFrom-Json to avoid line-by-line parsing edge cases.
  • Add a new Test-GlobalJsonVersions scenario covering leading newline/whitespace (and a leading comment case).
  • Add new global.json fixtures under nuget/updater/test-data/global-json-whitespace/.
Show a summary per file
File Description
nuget/updater/common.ps1 Switches global.json reading to Get-Content -Raw before JSON conversion.
nuget/updater/test.ps1 Adds a regression test case for global.json files with leading whitespace/newlines.
nuget/updater/test-data/global-json-whitespace/leading-whitespace/global.json Fixture: global.json starting with indentation before {.
nuget/updater/test-data/global-json-whitespace/leading-newline/global.json Fixture: global.json starting with a blank line.
nuget/updater/test-data/global-json-whitespace/leading-comment/global.json Fixture: global.json starting with a // comment line.

Copilot's findings

  • Files reviewed: 5/5 changed files
  • Comments generated: 0

@brettfo brettfo force-pushed the dev/brettfo/nuget-global-json-whitespace branch from ec4427e to 40d2a26 Compare May 20, 2026 21:09
@brettfo brettfo merged commit c0a1cdd into main May 20, 2026
106 checks passed
@brettfo brettfo deleted the dev/brettfo/nuget-global-json-whitespace branch May 20, 2026 21:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

L: dotnet:nuget NuGet packages via nuget or dotnet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants