Skip to content

Commit 186fd3e

Browse files
authored
fix: Sanitize formatted dates (#182)
1 parent 601b393 commit 186fd3e

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

src/card.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,18 @@
1212
function formatDate(string $dateString, string $format): string
1313
{
1414
$date = new DateTime($dateString);
15+
$formatted = "";
1516
// if current year, display only month and day
1617
if (date_format($date, "Y") == date("Y")) {
1718
// remove brackets and all text within them
18-
return date_format($date, preg_replace("/\[.*?\]/", "", $format));
19+
$formatted = date_format($date, preg_replace("/\[.*?\]/", "", $format));
1920
}
2021
// otherwise, display month, day, and year (just brackets removed)
21-
return date_format($date, str_replace(array("[", "]"), "", $format));
22+
else {
23+
$formatted = date_format($date, str_replace(array("[", "]"), "", $format));
24+
}
25+
// sanitize and return formatted date
26+
return htmlspecialchars($formatted);
2227
}
2328

2429
/**

0 commit comments

Comments
 (0)