Skip to content

REST API: Drop redundant absint() calls on comment post and parent IDs. - #16252

Open
adamsilverstein wants to merge 1 commit into
WordPress:trunkfrom
adamsilverstein:fix/66635-rest-comments-redundant-absint
Open

adamsilverstein wants to merge 1 commit into
WordPress:trunkfrom
adamsilverstein:fix/66635-rest-comments-redundant-absint

Conversation

@adamsilverstein

Copy link
Copy Markdown
Member

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

Follow up to #15853 for the two review comments @westonruter left after [65750] was committed.

Claude Code (Fable 5.2) went back through the review threads on the earlier PR and wrote this up:

Drops the absint() calls that [65750] added around $request['post'] and $request['parent'] in WP_REST_Comments_Controller. The comments schema declares both as integer with 'minimum' => 0, so the values are already non-negative integers when create_item() and update_item() read them.

Addresses:

The same commit added absint( $request['post'] ) in two more places, the get_comments() calls for the reaction uniqueness check and the duplicate cleanup in create_item(). Those are dropped as well, for the same reason.

Every other review thread on the earlier PR was already resolved before the commit, these two were the only ones left open. No behavior change is intended.

Note: at PHPStan level 10 the two check_note_parent() calls now report expects int, mixed given, since $request[...] is typed mixed. absint() was hiding that. The file is not in the strict path list and the rest of it reads $request values the same way, so core's own PHPStan run is not affected.

How has this been tested

  • vendor/bin/phpunit --filter WP_Test_REST_Comments_Controller passes (302 tests).
  • PHPCS is clean on the changed file.

Commit message

REST API: Drop redundant `absint()` calls on comment post and parent IDs.

The comments schema declares `post` and `parent` as integers with a minimum of 0, so the request values are already non-negative integers when `create_item()` and `update_item()` read them.

Follow-up to [65750].

Props westonruter.
See #66635.

AI Use

Claude Code (Fable 5.2) made the change and drafted this description from the review comments. I will review and test.

🤖 Generated with Claude Code

https://claude.ai/code/session_018vwYjSfCMNDQ1rP5mWYfTM

The comments schema declares `post` and `parent` as integers with a minimum
of 0, so the request values are already non-negative integers by the time
`create_item()` and `update_item()` read them.

Follow-up to [65750].

See #66635.

Claude-Session: https://claude.ai/code/session_018vwYjSfCMNDQ1rP5mWYfTM
@github-actions

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 adamsilverstein.

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 or WordPress.org 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.

@github-actions

Copy link
Copy Markdown

Test using WordPress Playground

The changes in this pull request can previewed and tested using a WordPress Playground instance.

WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser.

Some things to be aware of

  • All changes will be lost when closing a tab with a Playground instance.
  • All changes will be lost when refreshing the page.
  • A fresh instance is created each time the link below is clicked.
  • Every time this pull request is updated, a new ZIP file containing all changes is created. If changes are not reflected in the Playground instance,
    it's possible that the most recent build failed, or has not completed. Check the list of workflow runs to be sure.

For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation.

Test this pull request with WordPress Playground.

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

The review identifies no active issues, and the changes consistently rely on IDs already validated by the endpoint schema.

No open issues 🎉

What changed in this PR

This PR removes redundant absint() calls from REST comment creation and update paths because the endpoint schema already validates post and parent as non-negative integers.

Changes:

  • Pass validated request IDs directly to note-parent validation.
  • Use validated IDs directly in reaction uniqueness and duplicate-cleanup queries.
  • Remove redundant casts when determining post and parent IDs during note updates.
File Description
src/​wp-includes/​rest-api/​endpoints/​class-wp-rest-comments-controller.php Removes redundant integer casts from comment creation, reaction lookup, duplicate cleanup, and note update logic.

Review effort: Lite

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.

2 participants