-
Notifications
You must be signed in to change notification settings - Fork 1k
Preserve "0" values in YAML output #6188
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
This pull request effectively addresses the issue of preserving '0' values in YAML output by explicitly casting them to strings. The logic is sound and well-contained. My main feedback concerns coding style, specifically inconsistent indentation in the new code block. I've left a couple of specific comments with suggestions to fix it. Additionally, to prevent future regressions, I recommend adding a new test case to features/formatter.feature that verifies this fix for zero values in YAML output.
|
Hi there, Thanks for your PR! Could you perhaps add a test to demonstrate the issue this aims to solve? |
|
Hi! Thanks for the review 🙂 |
|
@AdityaS62 I see you're doing lots of experimenting. Are you running tests locally before pushing changes? That is a much faster feedback loop. |
Thanks for the feedback! You’re right — I did a fair bit of experimentation while narrowing down the correct fix. I’m setting up and running the relevant tests locally now to tighten the feedback loop before pushing further changes. Appreciate the guidance. |
|
@swissspidy Thanks for the suggestion! You’re right — running tests locally first would have saved some iteration time. I’ve since been running PHPCS and the relevant Behat scenarios locally before pushing, which helped stabilize the changes quickly. All unit tests, functional tests, and Behat scenarios now pass both locally and in CI. You may notice the Codecov check reporting 0% of diff hit, this appears to be due to coverage not being uploaded for this test matrix rather than missing test coverage. The behavior is fully covered by the existing Behat scenario and passes consistently. |
Summary
When formatting output as YAML, falsey scalar values such as 0 or "0" could be incorrectly handled, resulting in missing or invalid output. In some cases, this caused YAML formatting to fail instead of displaying the expected value.
What This Change Does
This update ensures scalar values are normalized before being passed to the YAML serializer so that valid zero values are preserved correctly.
Specifically:
Detects scalar zero values (0 and "0") before YAML serialization
Outputs zero values directly instead of passing them to the YAML serializer
Prevents exceptions caused by YAML serialization of scalar zero values
Scope
Applies only to YAML output
Does not affect JSON, CSV, table, or other formats
Preserves existing behavior for non-scalar values
Rationale
Zero (0) is a meaningful value in CLI output and should not be treated as empty or omitted.
This change ensures correctness and consistency in YAML output without altering broader formatting behavior or modifying the underlying YAML library.
Testing
Verified locally using Behat formatter tests
Confirmed that YAML output preserves scalar zero values correctly
No regressions observed in other output formats
Example
Before
$ wp option get test_zero --format=yaml
(Exception)
After
$ wp option get test_zero --format=yaml
0