Page MenuHomePhorge

Fix "strpos(): Non-string needles will be interpreted as strings" in PhutilSortVector
ClosedPublic

Authored by aklapper on Mar 22 2024, 10:26.
Tags
None
Referenced Files
F2185937: D25557.diff
Fri, May 10, 01:36
Unknown Object (File)
Sat, Apr 27, 22:29
Unknown Object (File)
Fri, Apr 26, 17:45
Unknown Object (File)
Fri, Apr 26, 17:45
Unknown Object (File)
Fri, Apr 26, 17:45
Unknown Object (File)
Thu, Apr 25, 22:58
Unknown Object (File)
Thu, Apr 25, 05:38
Unknown Object (File)
Mon, Apr 22, 22:57

Details

Summary

Code checking if the needle string $value is somewhere in the haystack "\0" makes no sense for a single byte (if it did, then strcmp instead of strpos should have been used) and the created exception output implies that it's supposed to check that a string does not contain NULL bytes.
Thus switch the order of arguments passed to strpos() to be correct.

EXCEPTION: (RuntimeException) strpos(): Non-string needles will be interpreted as strings in the future. Use an explicit chr() call to preserve the current behavior at [<arcanist>/src/error/PhutilErrorHandler.php:261]
  #0 <#2> PhutilErrorHandler::handleError(integer, string, string, integer, array) called at [<arcanist>/src/error/PhutilErrorHandler.php:261]
  #1 <#2> strpos(string, integer) called at [<arcanist>/src/utils/PhutilSortVector.php:33]

Closes T15755

Test Plan

Read the surrounding code carefully.

Diff Detail

Repository
rARC Arcanist
Branch
T15755 (branched from master)
Lint
Lint Passed
Unit
Tests Passed
Build Status
Buildable 1115
Build 1115: arc lint + arc unit

Event Timeline

sgtm

$ php --rf strpos
Function [ <internal:standard> function strpos ] {

  - Parameters [3] {
    Parameter #0 [ <required> string $haystack ]
    Parameter #1 [ <required> string $needle ]
    Parameter #2 [ <optional> int $offset = 0 ]
  }
  - Return [ int|false ]
}
This revision is now accepted and ready to land.Mar 22 2024, 10:29