Skip to content

Commit bb1d61a

Browse files
committed
Attempt to fix ext\standard\tests\file\basename_bug66395_variation2-win32.phpt and ext\standard\tests\file\pathinfo_basic1-win32.phpt
1 parent 5e01542 commit bb1d61a

File tree

1 file changed

+40
-9
lines changed

1 file changed

+40
-9
lines changed

ext/standard/string.c

Lines changed: 40 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1462,24 +1462,44 @@ PHP_FUNCTION(strtolower)
14621462
}
14631463
/* }}} */
14641464

1465+
#if defined(PHP_WIN32)
1466+
static bool _is_basename_start(const char *start, const char *pos)
1467+
{
1468+
if (pos - start >= 1
1469+
&& *(pos-1) != '/'
1470+
&& *(pos-1) != '\\') {
1471+
if (pos - start == 1) {
1472+
return 1;
1473+
} else if (*(pos-2) == '/' || *(pos-2) == '\\') {
1474+
return 1;
1475+
} else if (*(pos-2) == ':'
1476+
&& _is_basename_start(start, pos - 2)) {
1477+
return 1;
1478+
}
1479+
}
1480+
return 0;
1481+
}
1482+
#endif
1483+
14651484
/* {{{ php_basename */
14661485
PHPAPI zend_string *php_basename(const char *s, size_t len, const char *suffix, size_t suffix_len)
14671486
{
14681487
const char *basename_start;
14691488
const char *basename_end;
14701489

14711490
if (CG(ascii_compatible_locale)) {
1472-
#ifdef ZEND_WIN32
1473-
if ((len >= 2) && isalpha((int)((unsigned char *)s)[0]) && (s[1] == ':')) {
1474-
s += 2;
1475-
len -= 2;
1476-
}
1477-
#endif
1478-
14791491
basename_end = s + len - 1;
14801492

14811493
/* Strip trailing slashes */
1482-
while (basename_end >= s && IS_SLASH_P(basename_end)) {
1494+
while (basename_end >= s
1495+
#if defined(PHP_WIN32)
1496+
&& (*basename_end == '/'
1497+
|| *basename_end == '\\'
1498+
|| (*basename_end == ':'
1499+
&& _is_basename_start(s, basename_end)))) {
1500+
#else
1501+
&& *basename_end == '/') {
1502+
#endif
14831503
basename_end--;
14841504
}
14851505
if (basename_end < s) {
@@ -1489,7 +1509,18 @@ PHPAPI zend_string *php_basename(const char *s, size_t len, const char *suffix,
14891509
/* Extract filename */
14901510
basename_start = basename_end;
14911511
basename_end++;
1492-
while (basename_start > s && !IS_SLASH_P(basename_start - 1)) {
1512+
while (basename_start > s
1513+
#if defined(PHP_WIN32)
1514+
&& *(basename_start-1) != '/'
1515+
&& *(basename_start-1) != '\\') {
1516+
1517+
if (*(basename_start-1) == ':' &&
1518+
_is_basename_start(s, basename_start - 1)) {
1519+
break;
1520+
}
1521+
#else
1522+
&& *(basename_start-1) != '/') {
1523+
#endif
14931524
basename_start--;
14941525
}
14951526
} else {

0 commit comments

Comments
 (0)