timestamp: Hide timestamp forrmat errors in local echo.

This commit is contained in:
Rohitt Vashishtha
2020-07-06 21:00:53 +05:30
committed by Tim Abbott
parent 3d0a5d28f2
commit 0b510cd66d
2 changed files with 12 additions and 5 deletions

View File

@@ -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.

View File

@@ -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",