From 68015cb3eb98ac72114d60b19741b9bcc9ba0d34 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20D=C3=BCsterhus?= Date: Thu, 9 Apr 2026 15:55:37 +0200 Subject: [PATCH 1/2] version_compare: Fix handling of version numbers with a trailing dot --- ext/standard/tests/versioning/version_compare.phpt | 5 +++++ ext/standard/versioning.c | 10 +++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/ext/standard/tests/versioning/version_compare.phpt b/ext/standard/tests/versioning/version_compare.phpt index 07550dd410f4..e22ddabfa56b 100644 --- a/ext/standard/tests/versioning/version_compare.phpt +++ b/ext/standard/tests/versioning/version_compare.phpt @@ -22,6 +22,9 @@ foreach ($special_forms as $f1) { test("1.0$f1", "1.0$f2"); } } +test("1.2.", "1.2."); +test("1.2..", "1.2.."); + print "TESTING OPERATORS\n"; foreach ($special_forms as $f1) { foreach ($special_forms as $f2) { @@ -106,6 +109,8 @@ TESTING COMPARE 1.0pl1 > 1.0rc1 1.0pl1 > 1.0 1.0pl1 = 1.0pl1 +1.2. = 1.2. +1.2.. = 1.2.. TESTING OPERATORS 1.0-dev lt 1.0-dev : false 1.0-dev < 1.0-dev : false diff --git a/ext/standard/versioning.c b/ext/standard/versioning.c index 6995569fbf87..0ec061d0d86e 100644 --- a/ext/standard/versioning.c +++ b/ext/standard/versioning.c @@ -68,7 +68,15 @@ php_canonicalize_version(const char *version) } lp = *p++; } - *q++ = '\0'; + + /* Check if the last component is empty (i.e. the last character is a dot) + * and remove it if it is. */ + if (*(q - 1) == '.') { + *(q - 1) = '\0'; + } else { + *q = '\0'; + } + return buf; } From 7c3dcbb86901b79417ff646a527ce3f5a5a5e3b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20D=C3=BCsterhus?= Date: Tue, 28 Apr 2026 22:06:38 +0200 Subject: [PATCH 2/2] NEWS --- NEWS | 3 +++ 1 file changed, 3 insertions(+) diff --git a/NEWS b/NEWS index b110b17bef21..ef713ddd7255 100644 --- a/NEWS +++ b/NEWS @@ -2,6 +2,9 @@ PHP NEWS ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| ?? ??? ????, PHP 8.4.22 +- Standard: + . Fixed bug GH-21689 (version_compare() incorrectly handles versions ending + with a dot). (timwolla) 07 May 2026, PHP 8.4.21