Skip to content

Commit

Permalink
Allow trailing commas in workload set json
Browse files Browse the repository at this point in the history
  • Loading branch information
dsplaisted committed Jul 12, 2023
1 parent 0fb6201 commit 2433fff
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,12 @@ public static WorkloadSet FromDictionaryForJson(IDictionary<string, string> dict
public static WorkloadSet FromJson(string json, SdkFeatureBand defaultFeatureBand)
{
#if USE_SYSTEM_TEXT_JSON
return FromDictionaryForJson(JsonSerializer.Deserialize<IDictionary<string, string>>(json)!, defaultFeatureBand);
var jsonSerializerOptions = new JsonSerializerOptions()
{
AllowTrailingCommas = true,
ReadCommentHandling = JsonCommentHandling.Skip
};
return FromDictionaryForJson(JsonSerializer.Deserialize<IDictionary<string, string>>(json, jsonSerializerOptions)!, defaultFeatureBand);
#else
return FromDictionaryForJson(JsonConvert.DeserializeObject<IDictionary<string, string>>(json)!, defaultFeatureBand);
#endif
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,32 @@ var sdkDirectoryWorkloadManifestProvider
.BeEquivalentTo("ios: 11.0.2/8.0.100", "android: 33.0.2-rc.1/8.0.200", "maui: 15.0.1-rc.456/8.0.200-rc.2");
}


[Fact]
public void WorkloadSetCanHaveTrailingCommasInJson()
{
Initialize("8.0.200");

CreateMockManifest(_manifestRoot, "8.0.100", "ios", "11.0.2", true);
CreateMockManifest(_manifestRoot, "8.0.200", "android", "33.0.2-rc.1", true);
CreateMockManifest(_manifestRoot, "8.0.200-rc.2", "maui", "15.0.1-rc.456", true);

CreateMockWorkloadSet(_manifestRoot, "8.0.200", "8.0.200", """
{
"ios": "11.0.2/8.0.100",
"android": "33.0.2-rc.1/8.0.200",
"maui": "15.0.1-rc.456/8.0.200-rc.2",
}
""");

var sdkDirectoryWorkloadManifestProvider
= new SdkDirectoryWorkloadManifestProvider(sdkRootPath: _fakeDotnetRootDirectory, sdkVersion: "8.0.200", userProfileDir: null, globalJsonPath: null);

GetManifestContents(sdkDirectoryWorkloadManifestProvider)
.Should()
.BeEquivalentTo("ios: 11.0.2/8.0.100", "android: 33.0.2-rc.1/8.0.200", "maui: 15.0.1-rc.456/8.0.200-rc.2");
}

[Theory]
[InlineData(false)]
[InlineData(true)]
Expand Down

0 comments on commit 2433fff

Please sign in to comment.