Bug #69268 [NEW]: version_compare returns wrongly when "special" characters are given

From: Date: Fri, 20 Mar 2015 09:35:54 +0000
Subject: Bug #69268 [NEW]: version_compare returns wrongly when "special" characters are given
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-191480@lists.php.net to get a copy of this message
From: anlutro at gmail dot com Operating system: Linux (Debian) PHP version: Irrelevant Package: *General Issues Bug Type: Bug Bug description:version_compare returns wrongly when "special" characters are given Description: ------------ When doing version_compare on strings that contain "special" characters like parenthesis or brackets, it returns entirely the wrong result. While this isn't an issue for 99% of version strings, one of our applications has the option of either providing a regular version string OR a datetime string with the git commit hash at the end (mostly for the developers' sake). We "solved" this by telling all developers submitting packages to our system to remove paranthesis or brackets from the git hash suffix. This behaviour is consistent across all PHP versions: http://3v4l.org/DaQQY Test script: --------------- <?php $v = '1.2.3 (59eda4e)'; var_dump(version_compare($v, $v)); var_dump(version_compare($v, $v, '<')); $v = '1.2.3 [59eda4e]'; var_dump(version_compare($v, $v)); var_dump(version_compare($v, $v, '<')); $v = '1.2.3 59eda4e'; var_dump(version_compare($v, $v)); var_dump(version_compare($v, $v, '<')); Expected result: ---------------- int(0) bool(false) int(0) bool(false) int(0) bool(false) Actual result: -------------- int(-1) bool(true) int(-1) bool(true) int(0) bool(false) -- Edit bug report at https://bugs.php.net/bug.php?id=69268&edit=1 -- Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=69268&r=trysnapshot54 Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=69268&r=trysnapshot55 Try a snapshot (trunk): https://bugs.php.net/fix.php?id=69268&r=trysnapshottrunk Fixed in SVN: https://bugs.php.net/fix.php?id=69268&r=fixed Fixed in release: https://bugs.php.net/fix.php?id=69268&r=alreadyfixed Need backtrace: https://bugs.php.net/fix.php?id=69268&r=needtrace Need Reproduce Script: https://bugs.php.net/fix.php?id=69268&r=needscript Try newer version: https://bugs.php.net/fix.php?id=69268&r=oldversion Not developer issue: https://bugs.php.net/fix.php?id=69268&r=support Expected behavior: https://bugs.php.net/fix.php?id=69268&r=notwrong Not enough info: https://bugs.php.net/fix.php?id=69268&r=notenoughinfo Submitted twice: https://bugs.php.net/fix.php?id=69268&r=submittedtwice register_globals: https://bugs.php.net/fix.php?id=69268&r=globals PHP 4 support discontinued: https://bugs.php.net/fix.php?id=69268&r=php4 Daylight Savings: https://bugs.php.net/fix.php?id=69268&r=dst IIS Stability: https://bugs.php.net/fix.php?id=69268&r=isapi Install GNU Sed: https://bugs.php.net/fix.php?id=69268&r=gnused Floating point limitations: https://bugs.php.net/fix.php?id=69268&r=float No Zend Extensions: https://bugs.php.net/fix.php?id=69268&r=nozend MySQL Configuration Error: https://bugs.php.net/fix.php?id=69268&r=mysqlcfg

« previous php.bugs (#191480) next »