Skip to content

Do not drop request fields whose value is 0, "0" or 0.0 - #907

Merged
Naoray merged 2 commits into
mollie:mainfrom
winklemad:fix/datatransformer-drops-zero-values
Aug 24, 2026
Merged

Naoray merged 2 commits into
mollie:mainfrom
winklemad:fix/datatransformer-drops-zero-values

Conversation

@winklemad

Copy link
Copy Markdown
Contributor

Fixes #906

DataTransformer::filterEmptyValues used !empty($value) || is_bool($value) to decide which request fields to keep. PHP's empty() also treats 0, "0" and 0.0 as empty, so those legitimate values were stripped from every outgoing request body and query — e.g. creating a payment with description "0" sent no description at all.

The intent, per the existing tests, is to remove only null and empty strings (booleans were already special-cased). This replaces the empty() check with explicit checks so that null, '' and [] are still stripped while 0, "0", 0.0 and false are preserved:

return $value !== null && $value !== '' && $value !== [];

The predicate is shared by both filter sites (the outer payload/query filter and the inner Arrayable filter), so this one change covers both — a 0-valued field inside an Address/Money object was affected the same way.

Added a regression test asserting that 0, "0" and 0.0 survive the transform while null and '' are still removed. It fails on main and passes with this change; the existing DataTransformer tests are unchanged and still pass.

winklemad and others added 2 commits August 23, 2026 20:29
DataTransformer::filterEmptyValues used empty(), which treats the
legitimate scalar values 0, "0" and 0.0 as empty, so any top-level
payload or query field equal to one of those was silently removed from
the outgoing request (e.g. a payment description of "0"). Only null,
empty strings and empty arrays are meant to be stripped; check for those
cases explicitly instead.
@Naoray
Naoray merged commit 5ad6201 into mollie:main Aug 24, 2026
6 checks passed
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.

DataTransformer silently drops request fields whose value is 0, "0" or 0.0

2 participants