Commit 60b3fa3c76f for php.net

commit 60b3fa3c76f54c56255c7b07c6543f7853958d2a
Author: Tim Düsterhus <tim@tideways-gmbh.com>
Date:   Tue Apr 28 23:52:44 2026 +0200

    version_compare: Fix handling of version numbers with a trailing dot (#21689)

diff --git a/NEWS b/NEWS
index b110b17bef2..ef713ddd725 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

diff --git a/ext/standard/tests/versioning/version_compare.phpt b/ext/standard/tests/versioning/version_compare.phpt
index 07550dd410f..e22ddabfa56 100644
--- a/ext/standard/tests/versioning/version_compare.phpt
+++ b/ext/standard/tests/versioning/version_compare.phpt
@@ -22,6 +22,9 @@
     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 @@ function test($v1, $v2) {
 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 6995569fbf8..0ec061d0d86 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;
 }