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.

rendered_markdown: Fix stream-topic parser.

Anders Kaseorgeae05ba0ae73
diff --git a/frontend_tests/node_tests/rendered_markdown.js b/frontend_tests/node_tests/rendered_markdown.js
index c0e798a9743..12576df8dae 100644
--- a/frontend_tests/node_tests/rendered_markdown.js
+++ b/frontend_tests/node_tests/rendered_markdown.js
@@ -148,19 +148,19 @@ run_test("stream-links", () => {
const $stream_topic = $.create("a.stream-topic");
$stream_topic.set_find_results(".highlight", false);
$stream_topic.attr("data-stream-id", stream.stream_id);
- $stream_topic.text("#random>topic name");
+ $stream_topic.text("#random > topic name > still the topic name");
$content.set_find_results("a.stream", $array([$stream]));
$content.set_find_results("a.stream-topic", $array([$stream_topic]));
// Initial asserts
assert.equal($stream.text(), "never-been-set");
- assert.equal($stream_topic.text(), "#random>topic name");
+ assert.equal($stream_topic.text(), "#random > topic name > still the topic name");
rm.update_elements($content);
// Final asserts
assert.equal($stream.text(), `#${stream.name}`);
- assert.equal($stream_topic.text(), `#${stream.name} > topic name`);
+ assert.equal($stream_topic.text(), `#${stream.name} > topic name > still the topic name`);
});
run_test("timestamp", () => {
diff --git a/static/js/rendered_markdown.js b/static/js/rendered_markdown.js
index 80a034adc8e..aebb854b9cd 100644
--- a/static/js/rendered_markdown.js
+++ b/static/js/rendered_markdown.js
@@ -142,14 +142,13 @@ export const update_elements = (content) => {
if (stream_id && !$(this).find(".highlight").length) {
// Display the current name for stream if it is not
// being displayed in search highlight.
- const text = $(this).text();
- const topic = text.split(">", 2)[1];
const stream_name = stream_data.maybe_get_stream_name(stream_id);
if (stream_name !== undefined) {
// If the stream has been deleted,
// stream_data.maybe_get_stream_name might return
// undefined. Otherwise, display the current stream name.
- $(this).text("#" + stream_name + " > " + topic);
+ const text = $(this).text();
+ $(this).text("#" + stream_name + text.slice(text.indexOf(" > ")));
}
}
});