Bug #69268 [Opn->Nab]: version_compare returns wrongly when "special" characters are given

From: Date: Mon, 16 Nov 2020 15:22:11 +0000
Subject: Bug #69268 [Opn->Nab]: version_compare returns wrongly when "special" characters are given
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-230388@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=69268&edit=1

 ID:                 69268
 Updated by:         cmb@php.net
 Reported by:        anlutro at gmail dot com
 Summary:            version_compare returns wrongly when "special"
                     characters are given
-Status:             Open
+Status:             Not a bug
 Type:               Bug
 Package:            *General Issues
 Operating System:   Linux (Debian)
 PHP Version:        Irrelevant
-Assigned To:        
+Assigned To:        cmb
 Block user comment: N
 Private report:     N

 New Comment:

<https://www.php.net/version_compare>:

| version_compare — Compares two "PHP-standardized" version number
| strings

"PHP-standardized" version numbers don't contain such "special"
characters.


Previous Comments:
------------------------------------------------------------------------
[2015-03-20 09:35:54] anlutro at gmail dot com

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 this bug report at https://bugs.php.net/bug.php?id=69268&edit=1


Thread (2 messages)

« previous php.bugs (#230388) next »