Skip to content

fix(tests): parse appsettings with comments in the CORS configuration tests - #1448

Open
maxiar wants to merge 1 commit into
fullstackhero:mainfrom
maxiar:fix/cors-tests-tolerate-appsettings-comments-upstream
Open

maxiar wants to merge 1 commit into
fullstackhero:mainfrom
maxiar:fix/cors-tests-tolerate-appsettings-comments-upstream

Conversation

@maxiar

@maxiar maxiar commented Oct 15, 2026

Copy link
Copy Markdown
Contributor

CorsConfigurationTests (from #1391) reads appsettings.json / appsettings.Production.json with a strict JsonDocument.Parse. The ASP.NET configuration loader accepts comments and trailing commas in those files, so the test is stricter than the runtime.

It doesn't show up here because the template's appsettings has no comments. It does show up as soon as a scaffolded project documents a setting inline, which is how many teams annotate config. The CORS tests then fail with an error that has nothing to do with CORS:

System.Text.Json.JsonReaderException : '/' is invalid after a value. Expected either ',', '}', or ']'. LineNumber: 67 | BytePositionInLine: 4.

The fix parses the files with JsonCommentHandling.Skip and AllowTrailingCommas, the same leniency as the config loader. The test only changes how it parses the files; its assertions are unchanged.

Verification

dotnet test src/Tests/Framework.Tests --filter CorsConfigurationTests   -> 12/12 pass

The run used -p:NuGetAudit=false, because main currently fails restore on the crypto advisories that #1447 fixes. With a comment added to appsettings.json, the old parser throws and the new one passes.

🤖 Generated with Claude Code

… tests

The ASP.NET configuration loader accepts comments and trailing commas in
appsettings files, but CorsConfigurationTests reads them with a strict
JsonDocument.Parse. The first project that documents a setting inline (a
common thing to do in a scaffolded app) gets a JsonReaderException from a
test that has nothing to do with the comment. Parse with the same leniency.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant