markdown: Catch OverflowErrors in global times.

This also matches the except in the block above.
This commit is contained in:
Alex Vandiver
2024-12-06 14:38:44 +00:00
committed by Tim Abbott
parent 89bc073b5b
commit d2464ff52b
3 changed files with 10 additions and 3 deletions

View File

@@ -1,4 +1,4 @@
import {isValid} from "date-fns";
import {getUnixTime, isValid} from "date-fns";
import katex from "katex";
import _ from "lodash";
import assert from "minimalistic-assert";
@@ -580,7 +580,7 @@ function handleTimestamp(time_string: string): string {
}
const escaped_time = _.escape(time_string);
if (!isValid(timeobject)) {
if (!isValid(timeobject) || getUnixTime(timeobject) < 0) {
// Unsupported time format: rerender accordingly.
// We do not show an error on these formats in local echo because

View File

@@ -1455,7 +1455,7 @@ class Timestamp(markdown.inlinepatterns.Pattern):
if timestamp.tzinfo:
try:
timestamp = timestamp.astimezone(timezone.utc)
except ValueError:
except (ValueError, OverflowError):
error_element = Element("span")
error_element.set("class", "timestamp-error")
error_element.text = markdown.util.AtomicString(

View File

@@ -845,6 +845,13 @@
"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_overflow",
"input": "<time:0001-01-01T01:00:00+02:00>",
"expected_output": "<p><span class=\"timestamp-error\">Invalid time format: 0001-01-01T01:00:00+02:00</span></p>",
"marked_expected_output": "<p><span>0001-01-01T01:00:00+02:00</span></p>",
"text_content": "Invalid time format: 0001-01-01T01:00:00+02:00"
},
{
"name": "timestamp_unix",
"input": "Let's meet at <time:1496701800>.",