Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
composebox_typeahead: Fix bug in generating link syntax.
Kislay Verma676fbb6d99cf
diff --git a/web/src/composebox_typeahead.ts b/web/src/composebox_typeahead.tsindex b35e52f46dc..c1351a37cb2 100644--- a/web/src/composebox_typeahead.ts+++ b/web/src/composebox_typeahead.ts@@ -1233,7 +1233,8 @@ export function content_typeahead_selected(if (item.is_channel_link) {// The user opted to select only the stream and not specify a topic.- beginning = beginning.slice(0, syntax_start_index) + "#**" + stream_name + "** ";+ beginning = beginning.slice(0, syntax_start_index);+ beginning += topic_link_util.get_stream_link_syntax(stream_name) + " ";break;}beginning =diff --git a/web/src/topic_link_util.ts b/web/src/topic_link_util.tsindex cc102272b78..7c9c41a8745 100644--- a/web/src/topic_link_util.ts+++ b/web/src/topic_link_util.ts@@ -97,3 +97,12 @@ export function get_stream_topic_link_syntax(stream_name: string, topic_name: st}return `#**${stream_name}>${topic_name}**`;}++export function get_stream_link_syntax(stream_name: string): string {+ // If the topic name is such that it will generate an invalid #**stream>topic** syntax,+ // we revert to generating the normal markdown syntax for a link.+ if (will_produce_broken_stream_topic_link(stream_name)) {+ return get_fallback_markdown_link(stream_name);+ }+ return `#**${stream_name}**`;+}diff --git a/web/tests/topic_link_util.test.cjs b/web/tests/topic_link_util.test.cjsindex abeab0e22b4..8b2db84f058 100644--- a/web/tests/topic_link_util.test.cjs+++ b/web/tests/topic_link_util.test.cjs@@ -45,6 +45,19 @@ stream_data.add_sub(denmark_stream);stream_data.add_sub(dollar_stream);stream_data.add_sub(markdown_stream);+run_test("stream_link_syntax_test", () => {+ assert.equal(topic_link_util.get_stream_link_syntax("Sweden"), "#**Sweden**");+ assert.equal(topic_link_util.get_stream_link_syntax("Denmark"), "#**Denmark**");+ assert.equal(+ topic_link_util.get_stream_link_syntax("$$MONEY$$"),+ "[#$$MONEY$$](#narrow/channel/6-.24.24MONEY.24.24)",+ );+ assert.equal(+ topic_link_util.get_stream_link_syntax("Markdown [md]"),+ "[#Markdown [md]](#narrow/channel/7-Markdown-.5Bmd.5D)",+ );+});+run_test("stream_topic_link_syntax_test", () => {assert.equal(topic_link_util.get_stream_topic_link_syntax("Sweden", "topic"),