Skip to content

fix: nested array stored in DB for readonly dropdown#1197

Open
TarekRemo wants to merge 3 commits into
pluginsGLPI:mainfrom
TarekRemo:ticket_44062
Open

fix: nested array stored in DB for readonly dropdown#1197
TarekRemo wants to merge 3 commits into
pluginsGLPI:mainfrom
TarekRemo:ticket_44062

Conversation

@TarekRemo
Copy link
Copy Markdown

@TarekRemo TarekRemo commented May 15, 2026

Checklist before requesting a review

Please delete options that are not relevant.

  • I have performed a self-review of my code.
  • I have added tests (when available) that prove my fix is effective or that my feature works.
  • I have updated the CHANGELOG with a short functional description of the fix or new feature.

Description

  • It fixes ticket !44062.

  • Steps to reproduce:

    • Create a container with at least two multiple-dropdown custom fields : one set as readonly and one editable.
    • Open an item that has a value saved for the readonly dropdown (e.g. ["3"]).
    • Change the value of the editable dropdown and save the form.
    • Reload the page : a PHP error is thrown.
  • Root cause:

    • The dropdownField Twig macro pre-appends [] to the field name for all multiple inputs (e.g. plugin_fields_donefielddropdowns_id[]).
    • For readonly fields, Dropdown::show() renders hidden inputs and appends another [], producing plugin_fields_donefielddropdowns_id[][].
    • When the form is saved, PHP parses this double-bracketed name as a nested array ([['3']] instead of ['3']), which gets JSON-encoded as [["3"]] and stored corrupted in the database.
    • On the next page load, Dropdown::show() receives the decoded nested array, iterates over it, and tries to use an array as an array key inside isset(), triggering a PHP 8 TypeError.
  • Fix:

    • Before json_encode-ing a multiple field value for storage, flattenScalars() collapses any nested arrays into a flat list of scalars, preventing the corruption from ever reaching the database.
    • The same flattening is applied at display time so that values already corrupted in the database before this fix are handled.

@TarekRemo TarekRemo requested review from Rom1-B and stonebuzz May 15, 2026 13:25
@TarekRemo TarekRemo self-assigned this May 15, 2026
@TarekRemo TarekRemo added the bug label May 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant