Skip to content

Fix - Prevent TypeError in CheckboxesField::regex() when stored value is invalid JSON#3647

Open
RomainLvr wants to merge 1 commit into
support/2.13.0from
fix/checkboxesfield-regex-null-value
Open

Fix - Prevent TypeError in CheckboxesField::regex() when stored value is invalid JSON#3647
RomainLvr wants to merge 1 commit into
support/2.13.0from
fix/checkboxesfield-regex-null-value

Conversation

@RomainLvr

Copy link
Copy Markdown

Changes description

Checklist

Please check if your PR fulfills the following specifications:

  • Tests for the changes have been added
  • Docs have been added/updated

Description

  • It fixes !44948
  • Here is a brief description of what this PR does

When rendering the plugin_formcreator_solved_issues dashboard widget, a TypeError is thrown:

preg_grep(): Argument #2 ($array) must be of type array, null given

This happens when a form answer contains a checkbox field with a regex visibility condition, and the stored JSON value is corrupted or invalid. json_decode() returns null on invalid input, leaving $this->value = null, which then causes preg_grep() to throw.

A secondary bug was also found in LdapselectField::regex(), which incorrectly used preg_grep() on a plain string value instead of preg_match().

Changes

  • CheckboxesField::deserializeValue(): add is_array() guard after json_decode() so $this->value always ends up as an array, even when the stored data is malformed. This mirrors the existing pattern in ActorField.
  • LdapselectField::regex(): replace preg_grep() with preg_match(), consistent with RadiosField which holds a single string value.
  • tests/CheckboxesField.php: add testRegex() covering valid match, no match, invalid JSON, and JSON-null cases.

@RomainLvr RomainLvr self-assigned this Jun 26, 2026
@RomainLvr RomainLvr requested a review from stonebuzz June 26, 2026 13:19
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.

1 participant