Skip to content

Trim whitespace from --exclude entries in core and plugin verify-checksums#156

Closed
alaminfirdows wants to merge 2 commits into
wp-cli:mainfrom
alaminfirdows:fix/exclude-whitespace-trim
Closed

Trim whitespace from --exclude entries in core and plugin verify-checksums#156
alaminfirdows wants to merge 2 commits into
wp-cli:mainfrom
alaminfirdows:fix/exclude-whitespace-trim

Conversation

@alaminfirdows

Copy link
Copy Markdown
Contributor

Summary

  • explode( ',', $exclude ) in both Checksum_Core_Command and Checksum_Plugin_Command produces entries with leading/trailing spaces when the user writes a comma-separated list with spaces (e.g. "a, b, c").
  • The downstream in_array( ..., true ) strict comparison means ' b' !== 'b', so those entries silently match nothing.
  • Fix: wrap with array_map( 'trim', ... ) so "a, b" and "a,b" behave identically.

Changes

  • src/Checksum_Core_Command.php line 129: array_map( 'trim', explode( ',', $exclude ) )
  • src/Checksum_Plugin_Command.php line 106: array_map( 'trim', explode( ',', $exclude ) )
  • features/checksum-core.feature: new scenario covering spaced exclude list
  • features/checksum-plugin.feature: new scenario covering leading-space exclude entry

Testing

# Before fix — only "readme.html" skipped, "wp-includes/some-filename.php" not excluded
wp core verify-checksums --exclude='readme.html, wp-includes/some-filename.php'

# After fix — both excluded, command succeeds
wp core verify-checksums --exclude='readme.html, wp-includes/some-filename.php'

Functional tests added in both .feature files covering the whitespace case.

Fixes: --exclude does not trim whitespace, so space-separated entries are silently not excluded.

Both core and plugin verify-checksums used explode(',', $exclude) without
trimming, causing entries like ' b' in 'a, b' to silently not match.
Wrap with array_map('trim', ...) so 'a, b' and 'a,b' behave identically.
Covers the case where users pass comma-separated values with surrounding
spaces (e.g. 'a, b') which should behave identically to 'a,b'.
@github-actions github-actions Bot added command:core-verify-checksums Related to 'core verify-checksums' command command:plugin-verify-checksums Related to 'plugin verify-checksums' command scope:testing Related to testing labels Jun 27, 2026
@codecov

codecov Bot commented Jun 27, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@alaminfirdows alaminfirdows marked this pull request as ready for review June 27, 2026 08:41
@alaminfirdows alaminfirdows requested a review from a team as a code owner June 27, 2026 08:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

command:core-verify-checksums Related to 'core verify-checksums' command command:plugin-verify-checksums Related to 'plugin verify-checksums' command scope:testing Related to testing

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant