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.

timestamp: Hide timestamp forrmat errors in local echo.

Rohitt Vashishtha0b510cd66d56
diff --git a/static/js/markdown.js b/static/js/markdown.js
index 4dc169159bf..537b8bed3cc 100644
--- a/static/js/markdown.js
+++ b/static/js/markdown.js
@@ -305,7 +305,12 @@ function handleTimestamp(time) {
const escaped_time = _.escape(time);
if (timeobject === null || !timeobject.isValid()) {
// Unsupported time format: rerender accordingly.
- return `<span class="timestamp-error">Invalid time format: ${escaped_time}</span>`;
+
+ // We do not show an error on these formats in local echo because
+ // there is a chance that the server would interpret it successfully
+ // and if it does, the jumping from the error message to a rendered
+ // timestamp doesn't look good.
+ return `<span>${escaped_time}</span>`;
}
// Use html5 <time> tag for valid timestamps.
diff --git a/zerver/tests/fixtures/markdown_test_cases.json b/zerver/tests/fixtures/markdown_test_cases.json
index db686a49add..17a1c807632 100644
--- a/zerver/tests/fixtures/markdown_test_cases.json
+++ b/zerver/tests/fixtures/markdown_test_cases.json
@@ -750,7 +750,7 @@
"name": "timestamp_backend_markdown_only",
"input": "<time:Jun 5th 2017, 10:30PM>",
"expected_output": "<p><time datetime=\"2017-06-05T22:30:00Z\">Jun 5th 2017, 10:30PM</time></p>",
- "marked_expected_output": "<p><span class=\"timestamp-error\">Invalid time format: Jun 5th 2017, 10:30PM</span></p>"
+ "marked_expected_output": "<p><span>Jun 5th 2017, 10:30PM</span></p>"
},
{
"name": "timestamp_backend_markdown_and_marked",
@@ -760,18 +760,20 @@
{
"name": "timestamp_invalid_input",
"input": "<time:<alert(1)>>",
- "expected_output": "<p><span class=\"timestamp-error\">Invalid time format: &lt;alert(1)</span>&gt;</p>"
+ "expected_output": "<p><span class=\"timestamp-error\">Invalid time format: &lt;alert(1)</span>&gt;</p>",
+ "marked_expected_output": "<p><span>&lt;alert(1)</span>&gt;</p>"
},
{
"name": "timestamp_timezone",
"input": "<time:31 Dec 2017 5:30 am IST>",
"expected_output": "<p><time datetime=\"2017-12-31T00:00:00Z\">31 Dec 2017 5:30 am IST</time></p>",
- "marked_expected_output": "<p><span class=\"timestamp-error\">Invalid time format: 31 Dec 2017 5:30 am IST</span></p>"
+ "marked_expected_output": "<p><span>31 Dec 2017 5:30 am IST</span></p>"
},
{
"name": "timestamp_incorrect",
"input": "<time:**hello world**>",
- "expected_output": "<p><span class=\"timestamp-error\">Invalid time format: **hello world**</span></p>"
+ "expected_output": "<p><span class=\"timestamp-error\">Invalid time format: **hello world**</span></p>",
+ "marked_expected_output": "<p><span>**hello world**</span></p>"
},
{
"name": "timestamp_unix",