🌐 AI搜索 & 代理 主页
Skip to content

Conversation

@adityaanurag0219
Copy link

Fix: Ensure YAML formatter outputs scalar values (e.g., 0, strings) correctly

Description

This PR resolves an issue where scalar values were incorrectly rendered by the YAML formatter in WP-CLI.
Previously, scalars such as 0 or "hello" were being output as YAML lists instead of simple scalar values.

Problem

When running commands with --format=yaml, scalar values were misrepresented:

$ wp option get blog_public --format=yaml
---
- 0

$ wp option get test_string --format=yaml
---
- hello

This behavior is inconsistent with expected YAML scalar formatting and can cause confusion or break automation pipelines that rely on precise YAML output.

Fix

  • Updated WP_CLI::print_value() in class-wp-cli.php to correctly detect and render scalar values.
  • Scalars (e.g., integers, strings) are now dumped as scalars, not arrays/lists.
  • Arrays and objects continue to use Spyc::YAMLDump as before.

Verification (After Fix)

$ wp option get blog_public --format=yaml
---
0

$ wp option get blog_public --format=json
"0"

$ wp option add test_string hello
$ wp option get test_string --format=yaml
---
hello

Tests

  • Added feature tests in features/yaml-scalar.feature to validate scalar output.
  • Verified locally with Behat (functional tests) and PHPUnit (unit tests).
  • Full test suite passes.

Checklist

  • Bug fix implemented in class-wp-cli.php
  • Feature tests added under features/yaml-scalar.feature
  • Verified locally with Behat & PHPUnit
  • Code style checked with composer run-script phpcs

Notes on CI Failures

  • codecov/patch: Shows 0% diff hit because Behat feature tests are not included in Codecov coverage reports. However, additional scenarios were added that do exercise the new code paths.

  • Functional tests on WP trunk + PHP nightly (MySQL/SQLite): These jobs are known to be unstable. All stable PHP/MySQL builds pass successfully, indicating this patch is safe.

Related Issue

Fixes #6094

- Updated  in  to handle scalar values properly in YAML.
- Added functional feature test  to verify YAML output for scalars and strings.
Previously, scalars like 0 and 'hello' were incorrectly rendered as YAML lists.
This patch updates the YAML formatter to correctly handle scalar values and
adds feature tests to verify output.
This patch updates YAML formatter logic to handle all scalar types (0, string,
null, true, false) correctly. Previously, scalars like 0 or null were incorrectly
rendered. Added feature tests for these cases to prevent regressions.
@adityaanurag0219 adityaanurag0219 requested a review from a team as a code owner November 20, 2025 18:46
@codecov
Copy link

codecov bot commented Nov 20, 2025

Codecov Report

❌ Patch coverage is 92.30769% with 1 line in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
php/class-wp-cli.php 92.30% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

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.

YAML output for "0"

2 participants