Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions ext/standard/VmInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -201,8 +201,8 @@ private static function canonicalizeVersion(string $version): string
$buf .= '.';
}
} elseif (
(!ctype_digit($lp) && ctype_digit($ch))
|| (ctype_digit($lp) && !ctype_digit($ch))
(self::isVersionNonDigitChar($lp) && self::isVersionDigitChar($ch))
|| (self::isVersionDigitChar($lp) && self::isVersionNonDigitChar($ch))
) {
if ('.' !== $lq) {
$buf .= '.';
Expand All @@ -224,6 +224,18 @@ private static function canonicalizeVersion(string $version): string
return $buf;
}

/** php-src versioning.c isdig(): digit excluding '.' */
private static function isVersionDigitChar(string $ch): bool
{
return ctype_digit($ch);
}

/** php-src versioning.c isndig(): non-digit excluding '.' */
private static function isVersionNonDigitChar(string $ch): bool
{
return !ctype_digit($ch) && '.' !== $ch;
}

private static function compareSpecialVersionForms(string $form1, string $form2): int
{
/** @var array<string, int> */
Expand Down
4 changes: 2 additions & 2 deletions lib/AOT/runtime/phpc_info.c
Original file line number Diff line number Diff line change
Expand Up @@ -192,8 +192,8 @@ static char *phpc_canonicalize_version(const char *version)
*q++ = '.';
}
} else if (
(!isdigit((unsigned char) lp) && isdigit((unsigned char) *p))
|| (isdigit((unsigned char) lp) && !isdigit((unsigned char) *p))
(!isdigit((unsigned char) lp) && '.' != lp && isdigit((unsigned char) *p))
|| (isdigit((unsigned char) lp) && !isdigit((unsigned char) *p) && '.' != *p)
) {
if ('.' != lq) {
*q++ = '.';
Expand Down
4 changes: 4 additions & 0 deletions test/compliance/VersionCompareVMTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ public static function providePHPTests(): \Generator
__DIR__.'/cases/stdlib/version_compare.phpt',
'version_compare.phpt'
);
yield 'version_compare_partial.phpt' => self::parsePHPT(
__DIR__.'/cases/stdlib/version_compare_partial.phpt',
'version_compare_partial.phpt'
);
}

public function setUp(): void
Expand Down
11 changes: 11 additions & 0 deletions test/compliance/cases/stdlib/version_compare_partial.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
--TEST--
stdlib version_compare shorter operand parity (#4796)
--FILE--
<?php
echo version_compare('8.2.31', '8.2', '>=') ? "ge\n" : "no\n";
echo version_compare('8.2', '8.2.31', '<=') ? "le\n" : "no\n";
echo version_compare('8.2.31', '8.2.0', '>=') ? "ge0\n" : "no\n";
--EXPECT--
ge
le
ge0
4 changes: 4 additions & 0 deletions test/tmp/repro-version-compare-partial.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?php
declare(strict_types=1);
var_export(version_compare('8.2.31', '8.2', '>='));
echo PHP_EOL;