Skip to content

Fix calendar crash when yearmatchgroup regex does not match - #4239

Merged
KristjanESPERANTO merged 2 commits into
MagicMirrorOrg:developfrom
Antra:calendar-custom-event-fixes
Aug 29, 2026
Merged

Fix calendar crash when yearmatchgroup regex does not match#4239
KristjanESPERANTO merged 2 commits into
MagicMirrorOrg:developfrom
Antra:calendar-custom-event-fixes

Conversation

@Antra

@Antra Antra commented Aug 29, 2026

Copy link
Copy Markdown

Description

Fixes an issue in CalendarUtils.titleTransform() when a title transformation uses yearmatchgroup but the configured regular expression does not match the event title.

Currently, matchAll() returns an empty array when there is no match, but the code subsequently accesses yearmatch[0].length. This results in an exception and causes the calendar module to stop displaying its events.

This can occur when using yearmatchgroup for birthday events, for example, when some matching events have a birth year in the expected format while another event matching the keyword does not.

Change

Check that yearmatch contains at least one match before accessing yearmatch[0].

This is a one-line change and leaves the existing behaviour unchanged when the regular expression matches.

Example

With a transformation such as:

transform: {
    search: "^(.+) \\((\\d{4})\\)$",
    replace: "$1 ($2)",
    yearmatchgroup: 2
}

an event such as:

Test Birthday (1987)

continues to be transformed to:

Test Birthday (39)

while an event matching the custom-event keyword but not the year pattern no longer causes the calendar module to fail.

@KristjanESPERANTO

Copy link
Copy Markdown
Collaborator

Looks good! 👍 Would you like to add a regression test for this?

@paglasami7-pixel

This comment was marked as spam.

@paglasami7-pixel

This comment was marked as spam.

@Antra

Antra commented Aug 29, 2026

Copy link
Copy Markdown
Author

Looks good! 👍 Would you like to add a regression test for this?

Certainly, there is now also a small regression test for it added.

@paglasami7-pixel

This comment was marked as spam.

@KristjanESPERANTO
KristjanESPERANTO merged commit 762e1bc into MagicMirrorOrg:develop Aug 29, 2026
13 checks passed
@KristjanESPERANTO

Copy link
Copy Markdown
Collaborator

Nice! Thank you 😃

The change will be in the October release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants