Skip to content

Commit 60b3fa3

Browse files
authored
version_compare: Fix handling of version numbers with a trailing dot (#21689)
1 parent 171b722 commit 60b3fa3

3 files changed

Lines changed: 17 additions & 1 deletion

File tree

NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ PHP NEWS
22
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
33
?? ??? ????, PHP 8.4.22
44

5+
- Standard:
6+
. Fixed bug GH-21689 (version_compare() incorrectly handles versions ending
7+
with a dot). (timwolla)
58

69
07 May 2026, PHP 8.4.21
710

ext/standard/tests/versioning/version_compare.phpt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ foreach ($special_forms as $f1) {
2222
test("1.0$f1", "1.0$f2");
2323
}
2424
}
25+
test("1.2.", "1.2.");
26+
test("1.2..", "1.2..");
27+
2528
print "TESTING OPERATORS\n";
2629
foreach ($special_forms as $f1) {
2730
foreach ($special_forms as $f2) {
@@ -106,6 +109,8 @@ TESTING COMPARE
106109
1.0pl1 > 1.0rc1
107110
1.0pl1 > 1.0
108111
1.0pl1 = 1.0pl1
112+
1.2. = 1.2.
113+
1.2.. = 1.2..
109114
TESTING OPERATORS
110115
1.0-dev lt 1.0-dev : false
111116
1.0-dev < 1.0-dev : false

ext/standard/versioning.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,15 @@ php_canonicalize_version(const char *version)
6868
}
6969
lp = *p++;
7070
}
71-
*q++ = '\0';
71+
72+
/* Check if the last component is empty (i.e. the last character is a dot)
73+
* and remove it if it is. */
74+
if (*(q - 1) == '.') {
75+
*(q - 1) = '\0';
76+
} else {
77+
*q = '\0';
78+
}
79+
7280
return buf;
7381
}
7482

0 commit comments

Comments
 (0)