Skip to content

[5.4] Fix crash in Calendar field with invalid date format#46833

Merged
muhme merged 8 commits intojoomla:5.4-devfrom
krishnagandhicode:fix-calendar-crash
Feb 5, 2026
Merged

[5.4] Fix crash in Calendar field with invalid date format#46833
muhme merged 8 commits intojoomla:5.4-devfrom
krishnagandhicode:fix-calendar-crash

Conversation

@krishnagandhicode
Copy link
Copy Markdown
Contributor

@krishnagandhicode krishnagandhicode commented Feb 4, 2026

Pull Request fixes #46708

Summary of Changes

This PR fixes a fatal error (Call to a member function format() on bool) that occurs when a Calendar field receives an invalid date format.

Previously, CalendarField::filter() did not check if DateTime::createFromFormat() failed (returned false), leading to a crash when calling ->format() when the result is boolean.

Testing Instructions

  1. Create a Custom Field of type "Calendar"
  2. Create or Edit an Article
  3. In the Calendar field, manually type an invalid date. Use a format that breaks your specific language settings - for eg:
    • For English (Y-m-d): Type 202655-02-04
    • For French/German (d-m-Y): Type 01-01-200566
  4. save.

Actual result BEFORE applying this Pull Request

The site crashes with 0 Call to a member function format() on bool.

Expected result AFTER applying this Pull Request

The site displays a Error Page (Exception) with a clear message identifying the specific field:
"An error has occurred. 0 Invalid field: Start Publishing" (or the label of the specific field being tested, e.g: "Invalid field: Created Date").

The save is blocked, and the page reloads gracefully.

A specific error message appears identifying the broken field: "Invalid field: Start Publishing" (or the label of your custom field).

Note: I am relatively new to contributing to the core codebase, I am very open to feedback, If there is a preferred way to handle the translation keys or validation logic, I would appreciate your guidance!

Link to documentations

Please select:

  • Documentation link for guide.joomla.org:

  • No documentation changes for guide.joomla.org needed

  • Pull Request link for manual.joomla.org:

  • No documentation changes for manual.joomla.org needed

@richard67 richard67 changed the title [5.4] Fix crash in Calendar field with invalid date formmat [5.4] Fix crash in Calendar field with invalid date format Feb 4, 2026
@richard67 richard67 added the bug label Feb 4, 2026
@richard67
Copy link
Copy Markdown
Member

@krishnagandhicode Please fix the code style errors reported here: https://github.com/joomla/joomla-cms/actions/runs/21680625878/job/62514601493?pr=46833

First of all use spaces and not tabs for indentation.

@krishnagandhicode
Copy link
Copy Markdown
Contributor Author

@krishnagandhicode Please fix the code style errors reported here: https://github.com/joomla/joomla-cms/actions/runs/21680625878/job/62514601493?pr=46833

First of all use spaces and not tabs for indentation.

Thanks, on it : )

@brianteeman
Copy link
Copy Markdown
Contributor

Note for testers - you don't need to create a custom field. Any calendar field such as start publishing can be used

@mariantanase
Copy link
Copy Markdown

I cannot reproduce the issue.
On "Start publishing" field I type 05-02-2026 (d-m-Y).
When I click save, the article is saved without errors, but the date is changed to 2010-08-19 00:00:00

P.S. I did not create a custom field (as suggested by Brian).

@krishnagandhicode
Copy link
Copy Markdown
Contributor Author

krishnagandhicode commented Feb 5, 2026

I cannot reproduce the issue. On "Start publishing" field I type 05-02-2026 (d-m-Y). When I click save, the article is saved without errors, but the date is changed to 2010-08-19 00:00:00

P.S. I did not create a custom field (as suggested by Brian).

@mariantanase Thanks for testing.

To reproduce the Fatal Error (Crash), please try this:- Enter: 202655-02-04 (Year 202655)

That should trigger the fatal exception we are trying to fix.

@mariantanase
Copy link
Copy Markdown

Before applying the patch I've tried with this: 202655-02-04
error-calendar-date-before

After applying the patch, I've tried with the same sample date: 202655-02-04.
The error is different.
error-calendar-date-after

@mariantanase
Copy link
Copy Markdown

Now, after applying the patch, the error is:
error-calendar-date-after2

@krishnagandhicode
Copy link
Copy Markdown
Contributor Author

Now, after applying the patch, the error is: error-calendar-date-after2

Thanks for the re-test, @mariantanase!

yes, that is the intended behavior now - it correctly identifies the specific field label in the exception message.
also I have updated the PR description to match this result for better clarity.

@richard67
Copy link
Copy Markdown
Member

@mariantanase So your test result looks like a successful test to me. If you agree, please go to this PR in the issue tracker here https://issues.joomla.org/tracker/joomla-cms/46833 and use the blue "Test this" button at the top left corner to submit your test result. Thanks in advance, and thanks for testing.

@mariantanase
Copy link
Copy Markdown

I have tested this item ✅ successfully on 83b1c50


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/46833.

@exlemor
Copy link
Copy Markdown

exlemor commented Feb 5, 2026

I have tested this item ✅ successfully on 83b1c50

I have successfully tested this @krishnagandhicode.


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/46833.

@krishnagandhicode
Copy link
Copy Markdown
Contributor Author

krishnagandhicode commented Feb 5, 2026

I have tested this item ✅ successfully on 83b1c50I have successfully tested this @krishnagandhicode.

This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/46833.

Thanks Emmanuel :)

@richard67
Copy link
Copy Markdown
Member

RTC - This PR is ok as bug fix in 5.4-dev as it does not change behaviour, only improves the error message.

But further improvements in future versions (6.x) might be useful. Or we remove the calendar field and use a generic one on the long run.


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/46833.

@joomla-cms-bot joomla-cms-bot added RTC This Pull Request is Ready To Commit labels Feb 5, 2026
@gioacchino54
Copy link
Copy Markdown

gioacchino54 commented Feb 5, 2026

I have tested this item ✅ successfully on 83b1c50

Test before applying the patch
image

An error has occurred.

0 Call to a member function format() on false

Test after applying the patch
image

An error has occurred.

0 0 Invalid field: Calendar


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/46833.

@muhme
Copy link
Copy Markdown
Contributor

muhme commented Feb 5, 2026

✅ Final test before merge using JBT

  • Before PR created custom field birthday exception seen in using year 12026 instead of 2026 Call to a member function format() on false
  • Applied PR with Patch Tester
  • Still POST with 500 Internal Server Error, shown is An error has occurred. 0 Invalid field: birthday, browser back can be used and date with correct format saved
  • Tried wrong date format on 'Start Publishing' and getting Invalid field: Start Publishing

@muhme muhme merged commit 1ccc15c into joomla:5.4-dev Feb 5, 2026
69 checks passed
@joomla-cms-bot joomla-cms-bot removed the RTC This Pull Request is Ready To Commit label Feb 5, 2026
@muhme
Copy link
Copy Markdown
Contributor

muhme commented Feb 5, 2026

Thank you @krishnagandhicode for your contribution. Thank you @richard67, @Fedik and @brianteeman for your support. Thank you @mariantanase, @exlemor and @gioacchino54 for testing.

@muhme muhme added this to the Joomla! 5.4.3 milestone Feb 5, 2026
@krishnagandhicode krishnagandhicode deleted the fix-calendar-crash branch February 5, 2026 19:22
sathwikre pushed a commit to sathwikre/joomla-cms that referenced this pull request Feb 9, 2026
…6833)

* [5.4] Fix crash in Calendar field with invalid date format
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Call to a member function format() on false on calendar custom field with wrong date format

10 participants