Skip to content

Filesystem API: Return false from path_is_absolute() for non-string values - #14895

Open
bluefairydevelopment wants to merge 1 commit into
WordPress:trunkfrom
bluefairydevelopment:fix/59729-path-is-absolute-non-string
Open

bluefairydevelopment wants to merge 1 commit into
WordPress:trunkfrom
bluefairydevelopment:fix/59729-path-is-absolute-non-string

Conversation

@bluefairydevelopment

Copy link
Copy Markdown

path_is_absolute() reads $path[0], so a non-string value raises "Trying to access array offset on int/float/bool" warnings, and an array throws a TypeError from strpos() in wp_is_stream(). As the reporter found in a client's logs, this happens in ordinary code such as path_join( $path, get_the_ID() ).

Only a string can be an absolute path, so this returns false early for anything else, as proposed in the reporter's patch on the ticket. No real result changes: a number, boolean, null or array was never an absolute path. As a side effect, path_join( '/foo', 123 ) now returns /foo/123 without warnings.

Tests

  • New test_path_is_absolute_returns_false_for_non_string, covering an integer, 0, a float, true, null and an array.
  • New test_path_join_with_integer_path.
  • Without the fix: all 7 cases error, with the reported warning, or a TypeError for the array.
  • With the fix: all pass, along with the existing path_is_absolute() / path_join() tests.
  • --group functions: trunk 1,316 tests and the fix 1,323 tests, the difference being the 7 new cases. Neither run has any failures or errors, and the 27 warnings are identical. Run on PHP 8.5 / MariaDB 10.11.
  • phpcs: no new warnings.

Props mt8.biz.

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

Use of AI Tools

AI assistance: Yes
Tool(s): Claude Code
Model(s): Claude Opus 5.5
Used for: reading the ticket and the code, the fix, and the tests, including confirming that the tests fail without the fix and pass with it. Submitted by Blue Fairy Development, who are responsible for the change.


This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.

…alues.

Passing a non-string, such as a post ID through path_join(), read the
value as an array and raised warnings, or a TypeError for an array.
Only a string can be an absolute path, so return false early.

Props mt8.biz.
See #59729.
@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.

Unlinked Accounts

The following contributors have not linked their GitHub and WordPress.org accounts: @bluefairydevelopment.

Contributors, please read how to link your accounts to ensure your work is properly credited in WordPress releases.

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.

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

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.

1 participant