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
3 changes: 3 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
5 changes: 5 additions & 0 deletions ext/standard/tests/versioning/version_compare.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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
Expand Down
10 changes: 9 additions & 1 deletion ext/standard/versioning.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
Loading