From a34af372d00dee93951ffaf5944d99452d8cb324 Mon Sep 17 00:00:00 2001 From: Mike Lang Date: Sun, 21 Apr 2024 03:27:51 +1000 Subject: [PATCH] thrimbletrimmer: Validate chapter titles are ascii only We are not sure what characters are allowed in chapter titles. Emoji seem to be disallowed. It is unknown whether things like accents or smart quotes are allowed. To be conservative, we warn if there are any non-ascii characters in the chapter title. --- thrimbletrimmer/scripts/edit.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/thrimbletrimmer/scripts/edit.js b/thrimbletrimmer/scripts/edit.js index 61b5c0d..8277a62 100644 --- a/thrimbletrimmer/scripts/edit.js +++ b/thrimbletrimmer/scripts/edit.js @@ -825,6 +825,11 @@ function validateChapterDescription(chapterDescField) { if (chapterDesc.indexOf("<") !== -1 || chapterDesc.indexOf(">") !== -1) { chapterDescField.classList.add("input-error"); chapterDescField.title = "Chapter description may not contain angle brackets (< or >)"; + } else if (Array.from(chapterDesc).some(c => c.charCodeAt(0) > 127)) { // any char is non-ascii + // We don't know what chars are safe outside the ascii range, so we just warn on any of them. + // We know emoji are not safe. + chapterDescField.classList.add("input-error"); + chapterDescField.title = "Chapter descriptions with non-ascii characters may cause issues; proceed with caution"; } else { chapterDescField.classList.remove("input-error"); chapterDescField.title = "";