Skip to content

Commit 3d564ae

Browse files
committed
fix server error if a JSON file contains nested comments
1 parent 340ff4e commit 3d564ae

2 files changed

Lines changed: 14 additions & 3 deletions

File tree

docs/release-notes.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
* Reduced response times with a new analysis cache and client-side fetch.
1515
* Removed support for very old SMAPI logs.
1616
* You can now download a JSON representation of the parsed log (see the download link at the bottom of the log page).
17+
* Fixed server error if a JSON file contains nested comment syntax.
1718
* Third-party libraries are now served from `smapi.io` instead of external CDNs.
1819

1920
## 4.2.1

src/SMAPI.Web/Controllers/JsonValidatorController.cs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,9 +110,19 @@ public async Task<ViewResult> Index(string? schemaName = null, string? id = null
110110
}
111111

112112
// format JSON
113-
string formatted = parsed.ToString(Formatting.Indented);
114-
result.SetContent(formatted, oldExpiry: file.OldExpiry, newExpiry: file.NewExpiry, uploadWarning: file.Warning);
115-
parsed = JToken.Parse(formatted); // update line number references
113+
try
114+
{
115+
string formatted = parsed.ToString(Formatting.Indented);
116+
result.SetContent(formatted, oldExpiry: file.OldExpiry, newExpiry: file.NewExpiry, uploadWarning: file.Warning);
117+
parsed = JToken.Parse(formatted); // update line number references
118+
}
119+
catch
120+
{
121+
// In rare cases, Json.NET will convert valid JSON to invalid JSON. For example,
122+
// it will change `// remove /* */` to /*remove /* */*/` so it can't be parsed
123+
// anymore. If that happens, just keep the JSON as-is; at worst line numbers will
124+
// be slightly off if there are schema errors.
125+
}
116126
}
117127

118128
// skip if no schema selected

0 commit comments

Comments
 (0)