Skip to content

Commit 9e529f4

Browse files
committed
Merge branch 'PHP-8.5'
* PHP-8.5: version_compare: Fix handling of version numbers with a trailing dot (php#21689)
2 parents 777a79c + a29f36c commit 9e529f4

2 files changed

Lines changed: 14 additions & 1 deletion

File tree

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
@@ -66,7 +66,15 @@ php_canonicalize_version(const char *version)
6666
}
6767
lp = *p++;
6868
}
69-
*q++ = '\0';
69+
70+
/* Check if the last component is empty (i.e. the last character is a dot)
71+
* and remove it if it is. */
72+
if (*(q - 1) == '.') {
73+
*(q - 1) = '\0';
74+
} else {
75+
*q = '\0';
76+
}
77+
7078
return buf;
7179
}
7280

0 commit comments

Comments
 (0)