From: SomeoneStoleMyNickname Date: Fri, 4 Aug 2023 14:44:03 +0000 (+0200) Subject: Expanded the RegEx to check if the title contains new line caracters. Should fix... X-Git-Url: http://these/git/%7Bthis.captchaPngSrc%28%29%7D?a=commitdiff_plain;h=2531d051912f410fc949cc6eadcab020442064bb;p=lemmy-ui.git Expanded the RegEx to check if the title contains new line caracters. Should fix issue #1962 (#1965) * Expanded the RegEx to check if the title contains new line caracters. Should fix the issue #1962. Also added Comments for clarity. * ran yarn and changed according to recommendations --- diff --git a/src/shared/utils/helpers/valid-title.ts b/src/shared/utils/helpers/valid-title.ts index 8b146d3..a2057b9 100644 --- a/src/shared/utils/helpers/valid-title.ts +++ b/src/shared/utils/helpers/valid-title.ts @@ -2,7 +2,12 @@ export default function validTitle(title?: string): boolean { // Initial title is null, minimum length is taken care of by textarea's minLength={3} if (!title || title.length < 3) return true; - const regex = new RegExp(/.*\S.*/, "g"); + /* + Test if the Title is in a valid format: + (?=.*\S.*) checks if the title consists of only whitespace characters + (?=^[^\r\n]+$) checks if the title contains newlines + */ + const regex = new RegExp(/(?=(.*\S.*))(?=^[^\r\n]+$)/, "g"); return regex.test(title); }