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
This commit is contained in:
SomeoneStoleMyNickname 2023-08-04 16:44:03 +02:00 committed by GitHub
parent 8edf69559e
commit 2531d05191
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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} // Initial title is null, minimum length is taken care of by textarea's minLength={3}
if (!title || title.length < 3) return true; 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); return regex.test(title);
} }