mirror of https://github.com/zulip/zulip.git
markdown: Added error handling for invalid time zones.
If an invalid timezone (such as +32h) was provided, the timestamp.astimezone call would throw an exception, causing the message send to fail. Replace that with a user-facing error. Fixes #19658.
This commit is contained in:
parent
2035305b89
commit
753b8e1f6f
|
@ -1417,7 +1417,15 @@ class Timestamp(markdown.inlinepatterns.Pattern):
|
|||
# Use HTML5 <time> element for valid timestamps.
|
||||
time_element = Element("time")
|
||||
if timestamp.tzinfo:
|
||||
timestamp = timestamp.astimezone(timezone.utc)
|
||||
try:
|
||||
timestamp = timestamp.astimezone(timezone.utc)
|
||||
except ValueError:
|
||||
error_element = Element("span")
|
||||
error_element.set("class", "timestamp-error")
|
||||
error_element.text = markdown.util.AtomicString(
|
||||
f"Invalid time format: {time_input_string}"
|
||||
)
|
||||
return error_element
|
||||
else:
|
||||
timestamp = timestamp.replace(tzinfo=timezone.utc)
|
||||
time_element.set("datetime", timestamp.isoformat().replace("+00:00", "Z"))
|
||||
|
|
|
@ -838,6 +838,13 @@
|
|||
"marked_expected_output": "<p><span>**hello world**</span></p>",
|
||||
"text_content": "Invalid time format: **hello world**"
|
||||
},
|
||||
{
|
||||
"name": "timestamp_invalid_timezone",
|
||||
"input": "<time:1969-12-31T00:00:00+32:00>",
|
||||
"expected_output": "<p><span class=\"timestamp-error\">Invalid time format: 1969-12-31T00:00:00+32:00</span></p>",
|
||||
"marked_expected_output": "<p><span>1969-12-31T00:00:00+32:00</span></p>",
|
||||
"text_content": "Invalid time format: 1969-12-31T00:00:00+32:00"
|
||||
},
|
||||
{
|
||||
"name": "timestamp_unix",
|
||||
"input": "Let's meet at <time:1496701800>.",
|
||||
|
|
Loading…
Reference in New Issue