fix server error if a JSON file contains nested comments

This commit is contained in:
Jesse Plamondon-Willard
2025-04-07 21:38:54 -04:00
parent 340ff4e3b9
commit 3d564ae42c
2 changed files with 14 additions and 3 deletions
+1
View File
@@ -14,6 +14,7 @@
* Reduced response times with a new analysis cache and client-side fetch.
* Removed support for very old SMAPI logs.
* You can now download a JSON representation of the parsed log (see the download link at the bottom of the log page).
* Fixed server error if a JSON file contains nested comment syntax.
* Third-party libraries are now served from `smapi.io` instead of external CDNs.
## 4.2.1
@@ -110,9 +110,19 @@ internal class JsonValidatorController : Controller
}
// format JSON
string formatted = parsed.ToString(Formatting.Indented);
result.SetContent(formatted, oldExpiry: file.OldExpiry, newExpiry: file.NewExpiry, uploadWarning: file.Warning);
parsed = JToken.Parse(formatted); // update line number references
try
{
string formatted = parsed.ToString(Formatting.Indented);
result.SetContent(formatted, oldExpiry: file.OldExpiry, newExpiry: file.NewExpiry, uploadWarning: file.Warning);
parsed = JToken.Parse(formatted); // update line number references
}
catch
{
// In rare cases, Json.NET will convert valid JSON to invalid JSON. For example,
// it will change `// remove /* */` to /*remove /* */*/` so it can't be parsed
// anymore. If that happens, just keep the JSON as-is; at worst line numbers will
// be slightly off if there are schema errors.
}
}
// skip if no schema selected