Skip to content

Commit 40d2a26

Browse files
committed
handle errant whitespace in global.json
1 parent 2c592e7 commit 40d2a26

5 files changed

Lines changed: 27 additions & 1 deletion

File tree

nuget/updater/common.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ function Get-SdkVersionsToInstall([string] $repoRoot, [string[]] $updateDirector
1717
foreach ($globalJsonPath in $globalJsonPaths) {
1818
$resolvedGlobalJsonPath = Convert-Path "$repoRoot/$globalJsonPath"
1919
Write-LogMessage " Processing $globalJsonPath (resolved to $resolvedGlobalJsonPath) for SDK version information"
20-
$globalJson = Get-Content $resolvedGlobalJsonPath | ConvertFrom-Json
20+
$globalJson = Get-Content $resolvedGlobalJsonPath -Raw | ConvertFrom-Json
2121
if (@($globalJson.PSobject.Properties).Count -eq 0) {
2222
Write-LogMessage " No properties found in $globalJsonPath, skipping"
2323
continue
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// this is a leading comment
2+
{
3+
"sdk": {
4+
"version": "1.2.3-leading-comment"
5+
}
6+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
2+
{
3+
"sdk": {
4+
"version": "1.2.3-leading-newline"
5+
}
6+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"sdk": {
3+
"version": "1.2.3-leading-whitespace"
4+
}
5+
}

nuget/updater/test.ps1

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ $ErrorActionPreference = "Stop"
33

44
. $PSScriptRoot\common.ps1
55

6+
# uncomment line to enable detailed test logging
7+
#$env:DEPENDABOT_LOG_MESSAGES = "true"
8+
69
function Assert-ArraysEqual([string[]]$expected, [string[]]$actual) {
710
$expectedText = $expected -join ", "
811
$actualText = $actual -join ", "
@@ -102,6 +105,12 @@ try {
102105
-installedSdks @("8.0.404") `
103106
-expectedSdksToInstall @("9.0")
104107

108+
Test-GlobalJsonVersions `
109+
-testDirectory "global-json-whitespace" `
110+
-directories @("/leading-comment", "/leading-newline", "/leading-whitespace") `
111+
-installedSdks @("8.0.404") `
112+
-expectedSdksToInstall @("1.2.3-leading-comment", "1.2.3-leading-newline", "1.2.3-leading-whitespace")
113+
105114
Test-RequiredTargetingPacks `
106115
-testDirectory "targeting-packs" `
107116
-expectedTargetingPacks @("Some.Targeting.Pack.Ref/1.0.1", "Some.Other.Targeting.Pack.Ref/1.0.2", "Some.Targeting.Pack.Ref/4.0.1", "Some.Other.Targeting.Pack.Ref/4.0.2")

0 commit comments

Comments
 (0)