Repository navigation
Filesystem API: Return false from path_is_absolute() for non-string values - #14895
bluefairydevelopment wants to merge 1 commit into
Conversation
…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.
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. Unlinked AccountsThe 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 commandsYou can trigger Props Bot actions by commenting on this PR:
|
Test using WordPress PlaygroundThe 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
For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation. |
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 aTypeErrorfromstrpos()inwp_is_stream(). As the reporter found in a client's logs, this happens in ordinary code such aspath_join( $path, get_the_ID() ).Only a string can be an absolute path, so this returns
falseearly for anything else, as proposed in the reporter's patch on the ticket. No real result changes: a number, boolean,nullor array was never an absolute path. As a side effect,path_join( '/foo', 123 )now returns/foo/123without warnings.Tests
test_path_is_absolute_returns_false_for_non_string, covering an integer,0, a float,true,nulland an array.test_path_join_with_integer_path.TypeErrorfor the array.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.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.