Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion defaultmodules/calendar/calendarutils.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ const CalendarUtils = {
let replacement = transform.replace;
if (typeof transform.yearmatchgroup !== "undefined" && transform.yearmatchgroup !== "") {
const yearmatch = [...title.matchAll(needle)];
if (yearmatch[0].length >= transform.yearmatchgroup + 1 && yearmatch[0][transform.yearmatchgroup] * 1 >= 1900) {
if (yearmatch.length > 0 && yearmatch[0].length >= transform.yearmatchgroup + 1 && yearmatch[0][transform.yearmatchgroup] * 1 >= 1900) {
const calcage = new Date().getFullYear() - yearmatch[0][transform.yearmatchgroup] * 1;
const searchstr = `$${transform.yearmatchgroup}`;
replacement = replacement.replace(searchstr, calcage);
Expand Down
5 changes: 5 additions & 0 deletions tests/unit/modules/default/calendar/calendar_utils_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,5 +151,10 @@ describe("Calendar utils tests", () => {
const expectedResult = `Luciella (${new Date().getFullYear() - 2000}.)`;
expect(transformedTitle).toBe(expectedResult);
});

it("should not fail when the yearmatchgroup regex does not match", () => {
const transformedTitle = CalendarUtils.titleTransform("Test Birthday", [{ search: "^(.+) \\((\\d{4})\\)$", replace: "$1 ($2)", yearmatchgroup: 2 }]);
expect(transformedTitle).toBe("Test Birthday");
});
});
});