Skip to content

Commit 72e7c65

Browse files
committed
version_compare: Fix handling of version numbers with a trailing dot
1 parent 8972938 commit 72e7c65

2 files changed

Lines changed: 15 additions & 2 deletions

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: 10 additions & 2 deletions
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

@@ -178,7 +186,7 @@ php_version_compare(const char *orig_ver1, const char *orig_ver2)
178186
p2 = n2 + 1;
179187
}
180188
}
181-
if (compare == 0) {
189+
if (compare == 0 && (*p1 || *p2)) {
182190
if (n1 != NULL) {
183191
if (isdigit(*p1)) {
184192
compare = 1;

0 commit comments

Comments
 (0)