Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

topic_link_util: Add `[` and `]` as characters to escape.

Kislay Verma32f9ee7a62cd
diff --git a/web/src/topic_link_util.ts b/web/src/topic_link_util.ts
index 0fb484a33f7..06b7778a7ec 100644
--- a/web/src/topic_link_util.ts
+++ b/web/src/topic_link_util.ts
@@ -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;
}
diff --git a/web/tests/topic_link_util.test.cjs b/web/tests/topic_link_util.test.cjs
index 6e2f46f7ba4..60a823a930f 100644
--- a/web/tests/topic_link_util.test.cjs
+++ b/web/tests/topic_link_util.test.cjs
@@ -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");