topic_link_util: Add [ and ] as characters to escape.
Some checks failed
Code scanning / CodeQL (push) Has been cancelled
Zulip production suite / Ubuntu 22.04 production build (push) Has been cancelled
Zulip CI / ${{ matrix.name }} (zulip/ci:bookworm, true, false, Debian 12 (Python 3.11, backend + documentation), bookworm) (push) Has been cancelled
Zulip CI / ${{ matrix.name }} (zulip/ci:jammy, false, true, Ubuntu 22.04 (Python 3.10, backend + frontend), jammy) (push) Has been cancelled
Zulip CI / ${{ matrix.name }} (zulip/ci:noble, false, false, Ubuntu 24.04 (Python 3.12, backend), noble) (push) Has been cancelled
Zulip production suite / ${{ matrix.name }} (zulip/ci:bookworm, --test-custom-db, Debian 12 production install with custom db name and user, bookworm) (push) Has been cancelled
Zulip production suite / ${{ matrix.name }} (zulip/ci:jammy, , Ubuntu 22.04 production install and PostgreSQL upgrade with pgroonga, jammy) (push) Has been cancelled
Zulip production suite / ${{ matrix.name }} (zulip/ci:noble, , Ubuntu 24.04 production install, noble) (push) Has been cancelled
Zulip production suite / ${{ matrix.name }} (zulip/ci:bookworm-7.0, 7.0 Version Upgrade, bookworm) (push) Has been cancelled
Zulip production suite / ${{ matrix.name }} (zulip/ci:bookworm-8.0, 8.0 Version Upgrade, bookworm) (push) Has been cancelled
Zulip production suite / ${{ matrix.name }} (zulip/ci:jammy-6.0, 6.0 Version Upgrade, jammy) (push) Has been cancelled
Zulip production suite / ${{ matrix.name }} (zulip/ci:noble-9.0, 9.0 Version Upgrade, noble) (push) Has been cancelled

These characters cause the fallback markdown
links produced (#30071) to be broken.

Broken links are not produced when these are present
in `#**channel>topic**` syntax. It is only a problem
with the fallback markdown links.
This commit is contained in:
Kislay Verma 2025-01-25 17:21:02 +05:30 committed by Tim Abbott
parent f52ec0559c
commit 32f9ee7a62
2 changed files with 27 additions and 1 deletions

View File

@ -4,7 +4,7 @@ import * as internal_url from "../shared/src/internal_url.ts";
import * as stream_data from "./stream_data.ts";
const invalid_stream_topic_regex = /[`>*&]|(\$\$)/g;
const invalid_stream_topic_regex = /[`>*&[\]]|(\$\$)/g;
export function will_produce_broken_stream_topic_link(word: string): boolean {
return invalid_stream_topic_regex.test(word);
@ -22,6 +22,10 @@ export function escape_invalid_stream_topic_characters(text: string): string {
return "&";
case "$$":
return "$$";
case "[":
return "[";
case "]":
return "]";
default:
return text;
}

View File

@ -32,9 +32,18 @@ const dollar_stream = {
type: "stream",
};
const markdown_stream = {
name: "Markdown [md]",
description: "markdown",
stream_id: 7,
subscribed: true,
type: "stream",
};
stream_data.add_sub(sweden_stream);
stream_data.add_sub(denmark_stream);
stream_data.add_sub(dollar_stream);
stream_data.add_sub(markdown_stream);
run_test("stream_topic_link_syntax_test", () => {
assert.equal(
@ -78,11 +87,24 @@ run_test("stream_topic_link_syntax_test", () => {
topic_link_util.get_fallback_markdown_link("$$MONEY$$"),
"[#$$MONEY$$](#narrow/channel/6-.24.24MONEY.24.24)",
);
assert.equal(
topic_link_util.get_fallback_markdown_link("Markdown [md]"),
"[#Markdown [md]](#narrow/channel/7-Markdown-.5Bmd.5D)",
);
assert.equal(
topic_link_util.get_stream_topic_link_syntax("Sweden", "&ab"),
"[#Sweden > &ab](#narrow/channel/1-Sweden/topic/.26ab)",
);
assert.equal(
topic_link_util.get_stream_topic_link_syntax("Sweden", "&ab]"),
"[#Sweden > &ab]](#narrow/channel/1-Sweden/topic/.26ab.5D)",
);
assert.equal(
topic_link_util.get_stream_topic_link_syntax("Sweden", "&a[b"),
"[#Sweden > &a[b](#narrow/channel/1-Sweden/topic/.26a.5Bb)",
);
// Only for full coverage of the module.
assert.equal(topic_link_util.escape_invalid_stream_topic_characters("Sweden"), "Sweden");