topic_link_util: Add `&` as a character which can produce broken links.

`&` in topic names like `©` can result in broken stream topic
links. So we generate fallback markdown links for them too.

This is a follow up to #30071.
This commit is contained in:
Kislay Udbhav Verma 2024-10-19 21:53:56 +05:30 committed by Tim Abbott
parent f7750a07a2
commit 6956947a73
2 changed files with 8 additions and 1 deletions

View File

@ -4,7 +4,7 @@ import * as internal_url from "../shared/src/internal_url";
import * as stream_data from "./stream_data";
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);
@ -24,6 +24,8 @@ export function escape_invalid_stream_topic_characters(text: string): string {
return ">";
case "*":
return "*";
case "&":
return "&";
case "$$":
return "$$";
default:

View File

@ -83,6 +83,11 @@ run_test("stream_topic_link_syntax_test", () => {
"[#$$MONEY$$](#narrow/channel/6-.24.24MONEY.24.24)",
);
assert.equal(
topic_link_util.get_stream_topic_link_syntax("#**Sweden>&ab", "&ab"),
"[#Sweden>&ab](#narrow/channel/1-Sweden/topic/.26ab)",
);
// Only for full coverage of the module.
assert.equal(topic_link_util.escape_invalid_stream_topic_characters("Sweden"), "Sweden");
});