refactor(web): drop a length check the closed-set parse already makes (#61)
CI / Lint / Test / Vet (pull_request) Successful in 36s
CI / Build & Import (pull_request) Skipped
CI / Deploy via GitOps (pull_request) Skipped

The read is capped at 17 bytes and no valid language is longer than 4, so the parse
refuses anything the length check would; the mutant that removed it survived.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-04 22:31:03 +02:00
co-authored by Claude Sonnet 5.5
parent 0338b18a17
commit cc6fe7083d
+2 -2
View File
@@ -36,7 +36,7 @@ const (
// and the title field; the cap itself is enforced on the file part by Intake. // and the title field; the cap itself is enforced on the file part by Intake.
uploadOverhead = 1 << 20 uploadOverhead = 1 << 20
maxTitleRunes = 200 maxTitleRunes = 200
// maxLanguageBytes bounds the language field: the longest value is four bytes. // maxLanguageBytes bounds what is read of the language field; a valid value is at most four bytes, so a longer one fails the parse.
maxLanguageBytes = 16 maxLanguageBytes = 16
// uploadPollEvery is how often an unfinished upload re-asks for its status. // uploadPollEvery is how often an unfinished upload re-asks for its status.
uploadPollEvery = "2s" uploadPollEvery = "2s"
@@ -136,7 +136,7 @@ func (a *App) handleUploadPost(w http.ResponseWriter, r *http.Request) {
return return
} }
l, ok := domain.ParseLanguage(string(b)) l, ok := domain.ParseLanguage(string(b))
if !ok || len(b) > maxLanguageBytes { if !ok {
a.logger().Info("upload rejected", "reason", "language") a.logger().Info("upload rejected", "reason", "language")
a.renderUploadsPage(w, r, userID, http.StatusBadRequest, "Choose a language from the list.") a.renderUploadsPage(w, r, userID, http.StatusBadRequest, "Choose a language from the list.")
return return