Fix bug #51068 (glob:// do not support current path relative)

Fix DirectoryIterator glob://* current path relative queries
This commit is contained in:
Ahmed Abdou 2019-01-29 08:59:45 +01:00 committed by Nikita Popov
parent fe4d7248cc
commit ec28d4c247
4 changed files with 55 additions and 6 deletions

4
NEWS
View File

@ -10,6 +10,10 @@ PHP NEWS
. Support Oracle Database tracing attributes ACTION, MODULE,
CLIENT_INFO, and CLIENT_IDENTIFIER. (Cameron Porter)
- SPL:
. Fixed bug #51068 (DirectoryIterator glob:// don't support current path
relative queries). (Ahmed Abdou)
- Standard:
. Fixed bug #77552 (Unintialized php_stream_statbuf in stat functions).
(John Stevenson)

View File

@ -212,12 +212,21 @@ static inline void spl_filesystem_object_get_file_name(spl_filesystem_object *in
}
break;
case SPL_FS_DIR:
if (intern->file_name) {
efree(intern->file_name);
{
size_t path_len = 0;
char *path = spl_filesystem_object_get_path(intern, &path_len);
if (intern->file_name) {
efree(intern->file_name);
}
/* if there is parent path, ammend it, otherwise just use the given path as is */
if (path_len == 0) {
intern->file_name_len = spprintf(
&intern->file_name, 0, "%s", intern->u.dir.entry.d_name);
} else {
intern->file_name_len = spprintf(
&intern->file_name, 0, "%s%c%s", path, slash, intern->u.dir.entry.d_name);
}
}
intern->file_name_len = spprintf(&intern->file_name, 0, "%s%c%s",
spl_filesystem_object_get_path(intern, NULL),
slash, intern->u.dir.entry.d_name);
break;
}
} /* }}} */

View File

@ -0,0 +1,36 @@
--TEST--
SPL: glob wrapper interactions with DirectoryIterator
--FILE--
<?php
touch('bug.51068');
mkdir('bug.51068.dir');
touch('bug.51068.dir/lvl2.bug.51068');
$iter = new DirectoryIterator('glob://*.51068');
foreach ($iter as $f) {
var_dump($f->getFilename());
var_dump($f->getSize());
}
$iter = new DirectoryIterator('glob://bug.51068.dir/*.51068');
foreach ($iter as $f) {
var_dump($f->getFilename());
var_dump($f->getSize());
}
$iter = new DirectoryIterator('glob://bug.51068.dir');
foreach ($iter as $f) {
var_dump($f->getFilename());
var_dump($f->getSize() >= 0);
}
?>
--CLEAN--
<?php
unlink('bug.51068');
unlink('bug.51068.dir/lvl2.bug.51068');
rmdir('bug.51068.dir');
?>
--EXPECT--
string(9) "bug.51068"
int(0)
string(14) "lvl2.bug.51068"
int(0)
string(13) "bug.51068.dir"
bool(true)

View File

@ -128,7 +128,7 @@ static void php_glob_stream_path_split(glob_s_t *pglob, const char *path, int ge
if (pglob->path) {
efree(pglob->path);
}
if (path != gpath) {
if ((path - gpath) > 1) {
path--;
}
pglob->path_len = path - gpath;