diff options
author | Jesse Plamondon-Willard <Pathoschild@users.noreply.github.com> | 2022-08-16 22:03:22 -0400 |
---|---|---|
committer | Jesse Plamondon-Willard <Pathoschild@users.noreply.github.com> | 2022-08-16 22:03:22 -0400 |
commit | c51a593e93ba4d7e41971ed64cfa413449d501e3 (patch) | |
tree | 0cbdfc6fcd0044ad99ca51e1fe30381b79c25db0 | |
parent | f23cd450a0cca3ede1dacb198b4dd6432a44bf16 (diff) | |
download | SMAPI-c51a593e93ba4d7e41971ed64cfa413449d501e3.tar.gz SMAPI-c51a593e93ba4d7e41971ed64cfa413449d501e3.tar.bz2 SMAPI-c51a593e93ba4d7e41971ed64cfa413449d501e3.zip |
fix log parser error if a mod logged a null character
-rw-r--r-- | docs/release-notes.md | 3 | ||||
-rw-r--r-- | src/SMAPI.Web/Controllers/LogParserController.cs | 16 |
2 files changed, 14 insertions, 5 deletions
diff --git a/docs/release-notes.md b/docs/release-notes.md index 1734ca2d..5626dcc8 100644 --- a/docs/release-notes.md +++ b/docs/release-notes.md @@ -31,7 +31,8 @@ * Added log parser warning about performance of PyTK 1.23.0 or earlier. * Converted images to SVG (thanks to ishan!). * Updated log parser for new update alert format in SMAPI 3.15.1. - * Fixed parsing for invalid content packs. + * Fixed log parsing for invalid content packs. + * Fixed log parsing if a mod logged a null character. ## 3.15.1 Released 06 July 2022 for Stardew Valley 1.5.6 or later. diff --git a/src/SMAPI.Web/Controllers/LogParserController.cs b/src/SMAPI.Web/Controllers/LogParserController.cs index 33af5a81..a3bcf4c3 100644 --- a/src/SMAPI.Web/Controllers/LogParserController.cs +++ b/src/SMAPI.Web/Controllers/LogParserController.cs @@ -1,7 +1,9 @@ using System; -using System.Linq; +using System.Collections.Specialized; +using System.IO; using System.Text; using System.Threading.Tasks; +using System.Web; using Microsoft.AspNetCore.Mvc; using StardewModdingAPI.Toolkit.Utilities; using StardewModdingAPI.Web.Framework; @@ -87,9 +89,15 @@ namespace StardewModdingAPI.Web.Controllers public async Task<ActionResult> PostAsync() { // get raw log text - string? input = this.Request.Form["input"].FirstOrDefault(); - if (string.IsNullOrWhiteSpace(input)) - return this.View("Index", this.GetModel(null, uploadError: "The log file seems to be empty.")); + // note: avoid this.Request.Form, which fails if any mod logged a null character. + string? input; + { + using StreamReader reader = new StreamReader(this.Request.Body); + NameValueCollection parsed = HttpUtility.ParseQueryString(await reader.ReadToEndAsync()); + input = parsed["input"]; + if (string.IsNullOrWhiteSpace(input)) + return this.View("Index", this.GetModel(null, uploadError: "The log file seems to be empty.")); + } // upload log UploadResult uploadResult = await this.Storage.SaveAsync(input); |