@@ -1462,24 +1462,44 @@ PHP_FUNCTION(strtolower)
1462
1462
}
1463
1463
/* }}} */
1464
1464
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
+
1465
1484
/* {{{ php_basename */
1466
1485
PHPAPI zend_string * php_basename (const char * s , size_t len , const char * suffix , size_t suffix_len )
1467
1486
{
1468
1487
const char * basename_start ;
1469
1488
const char * basename_end ;
1470
1489
1471
1490
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
-
1479
1491
basename_end = s + len - 1 ;
1480
1492
1481
1493
/* 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
1483
1503
basename_end -- ;
1484
1504
}
1485
1505
if (basename_end < s ) {
@@ -1489,7 +1509,18 @@ PHPAPI zend_string *php_basename(const char *s, size_t len, const char *suffix,
1489
1509
/* Extract filename */
1490
1510
basename_start = basename_end ;
1491
1511
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
1493
1524
basename_start -- ;
1494
1525
}
1495
1526
} else {
0 commit comments