util: Do not use look-behind in wildcard mention checks.

92fa9ee78c switched this regex to match the server-side regex, but
Safari < 16.4 does not support look-behind in regexes.

Switch to matching on start-of-string or a positive character class.
This commit is contained in:
Alex Vandiver 2024-04-04 00:13:35 +00:00 committed by Anders Kaseorg
parent 6d5243148a
commit 01860422af
2 changed files with 6 additions and 1 deletions

View File

@ -195,7 +195,10 @@ export class CachedValue<T> {
}
export function find_stream_wildcard_mentions(message_content: string): string | null {
const mention = message_content.match(/(?<![^\s"'(/<[{])(@\*{2}(all|everyone|stream)\*{2})/);
// We cannot use the exact same regex as the server side users (in zerver/lib/mention.py)
// because Safari < 16.4 does not support look-behind assertions. Reframe the lookbehind of a
// negative character class as a start-of-string or positive character class.
const mention = message_content.match(/(?:^|[\s"'(/<[{])(@\*{2}(all|everyone|stream)\*{2})/);
if (mention === null) {
return null;
}

View File

@ -170,6 +170,8 @@ run_test("wildcard_mentions_regexp", () => {
"@**everyone**",
'"@**everyone**"',
"@**everyone**: Look at this!",
"The <@**everyone**> channel",
'I have to say "@**everyone**" to ding the bell',
"some text before @**everyone** some text after",
"@**everyone** some text after only",
"some text before only @**everyone**",