Skip to content

Tests: Cover stripslashes_from_strings_only() - #15325

Closed
devmuhib009 wants to merge 2 commits into
WordPress:trunkfrom
devmuhib009:tests/65819-cover-stripslashes-from-strings-only
Closed

devmuhib009 wants to merge 2 commits into
WordPress:trunkfrom
devmuhib009:tests/65819-cover-stripslashes-from-strings-only

Conversation

@devmuhib009

Copy link
Copy Markdown
Member

Trac ticket: https://core.trac.wordpress.org/ticket/65819

This PR extends Tests_Formatting_StripslashesDeep to cover stripslashes_from_strings_only():

  • Stripping slashes from string values
  • Preserving non-string data types (integers, floats, booleans, null, arrays)

@github-actions

github-actions Bot commented Nov 1, 2026 •

Copy link
Copy Markdown

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs.

Core Committers: Use this line as a base for the props when committing in SVN:

Props devmuhib, huzaifaalmesbah, lancewillett.

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.


Props Bot commands

You can trigger Props Bot actions by commenting on this PR:

  • @propsbot add <username> to give props to a GitHub user. Requires write access.
  • @propsbot remove <username> to leave a user out of the props. Requires write access.
  • @propsbot refresh to refresh this list. Adding the props-bot label works too.

@huzaifaalmesbah huzaifaalmesbah left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I left a few small notes inline.

AI Review: Opus 5.5

'float' => array( 3.14 ),
'boolean true' => array( true ),
'null' => array( null ),
'array' => array( array( 'a', 'b' ) ),

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one looks like a small coverage gap: array( 'a', 'b' ) has nothing to strip, so the test still passes if array items start getting stripped. A slashed item would catch it:

Suggested change
'array' => array( array( 'a', 'b' ) ),
'array' => array( array( "I can\'t", 'b' ) ),

*
* @ticket 65819
*
* @covers ::stripslashes_from_strings_only

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Optional: the class docblock already has @covers ::stripslashes_from_strings_only. Feel free to drop this one and the one at line 76.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The array fixture contains no backslashes, so the assertion cannot detect incorrect recursive stripping and needs a backslash-containing string to verify that non-string inputs remain unchanged.

1 open issue
What changed in this PR

This PR extends WordPress formatting tests to cover stripslashes_from_strings_only(), addressing Trac ticket #65819 without changing production code.

Changes:

  • Adds a test verifying slash removal from strings.
  • Adds data-driven checks that non-string values remain unchanged.
  • Adds coverage annotations for the helper.
File Description
tests/​phpunit/​tests/​formatting/​stripslashesDeep.php Adds string and non-string tests for stripslashes_from_strings_only().

Review effort: Balanced

@lancewillett lancewillett left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please narrow the added coverage. test_strips_slashes() already exercises this callback through stripslashes_deep(), and test_preserves_original_datatype() already protects integer/boolean preservation. The added string case repeats that regression check. Remove the duplicate string case and avoid repeating the scalar matrix solely for direct coverage. The direct-array contract is distinct, but the current unslashed array does not distinguish it; the existing inline feedback already explains that limitation. Removing redundant additions is sufficient—no additional test matrix is requested.

AI review · gpt-6

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No active review issues were identified for the focused array-preservation test addition.

No open issues 🎉

1 resolved since last review

Review effort: Balanced

@huzaifaalmesbah huzaifaalmesbah left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for refining this, @devmuhib009! Narrowing the test to stripslashes_from_strings_only()'s non-recursive array contract removes redundancy and cleanly verifies the unique behavior. LGTM!

AI Review: Gemini 3.8 Flash

@lancewillett lancewillett left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The narrowed test now distinguishes the documented behavior: an array containing a slashed string must pass through stripslashes_from_strings_only() unchanged. The existing recursive tests never pass an array directly to that callback. Removing the duplicate string/scalar cases was useful simplification.

The affected class passes randomized single-site and multisite runs (4 tests, 15 assertions each); PHPCS and CI pass. A controlled callback mutation passed the older tests but failed this new assertion. Approved at 728bb7b.

AI review · gpt-6

wporg-sync pushed a commit that referenced this pull request Nov 2, 2026
Verify that `stripslashes_from_strings_only()` leaves an array containing a slashed string unchanged. The existing `stripslashes_deep()` tests exercise recursive processing instead of this direct-input contract.

Developed in: #15325

Props devmuhib, huzaifaalmesbah.
See #65819.


git-svn-id: https://develop.svn.wordpress.org/trunk@65188 602fd350-edb4-49c9-b593-d223f7449a82
wporg-sync pushed a commit to WordPress/WordPress that referenced this pull request Nov 2, 2026
Verify that `stripslashes_from_strings_only()` leaves an array containing a slashed string unchanged. The existing `stripslashes_deep()` tests exercise recursive processing instead of this direct-input contract.

Developed in: WordPress/wordpress-develop#15325

Props devmuhib, huzaifaalmesbah.
See #65819.

Built from https://develop.svn.wordpress.org/trunk@65188


git-svn-id: http://core.svn.wordpress.org/trunk@64337 1a063a9b-81f0-0310-95a4-ce76da25c4cd
@lancewillett

Copy link
Copy Markdown
Member

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.

4 participants