mirror of
https://github.com/php/php-src.git
synced 2026-03-30 20:22:36 +02:00
simplify phar_get_link_location and increase its coverage to 100%
This commit is contained in:
BIN
ext/phar/tests/tar/files/tinylink.tar
Normal file
BIN
ext/phar/tests/tar/files/tinylink.tar
Normal file
Binary file not shown.
19
ext/phar/tests/tar/links4.phpt
Normal file
19
ext/phar/tests/tar/links4.phpt
Normal file
@@ -0,0 +1,19 @@
|
||||
--TEST--
|
||||
Phar: tar with link to root directory file from root directory file
|
||||
--SKIPIF--
|
||||
<?php if (!extension_loaded("phar")) die("skip"); ?>
|
||||
--FILE--
|
||||
<?php
|
||||
try {
|
||||
$p = new PharData(dirname(__FILE__) . '/files/tinylink.tar');
|
||||
} catch (Exception $e) {
|
||||
echo $e->getMessage() . "\n";
|
||||
}
|
||||
echo $p['file.txt']->getContent();
|
||||
echo $p['link.txt']->getContent();
|
||||
?>
|
||||
===DONE===
|
||||
--EXPECT--
|
||||
hi
|
||||
hi
|
||||
===DONE===
|
||||
@@ -28,22 +28,19 @@ extern php_stream_wrapper php_stream_phar_wrapper;
|
||||
/* for links to relative location, prepend cwd of the entry */
|
||||
static char *phar_get_link_location(phar_entry_info *entry TSRMLS_DC)
|
||||
{
|
||||
char *tmp, *p, *ret = NULL;
|
||||
char *p, *ret = NULL;
|
||||
if (!entry->link) {
|
||||
return NULL;
|
||||
}
|
||||
if (entry->link[0] == '/') {
|
||||
return estrdup(entry->link + 1);
|
||||
}
|
||||
tmp = estrndup(entry->filename, entry->filename_len);
|
||||
p = strrchr(tmp, '/');
|
||||
p = strrchr(entry->filename, '/');
|
||||
if (p) {
|
||||
*p = '\0';
|
||||
spprintf(&ret, 0, "%s/%s", tmp, entry->link);
|
||||
efree(tmp);
|
||||
spprintf(&ret, 0, "%s/%s", entry->filename, entry->link);
|
||||
return ret;
|
||||
}
|
||||
efree(ret);
|
||||
return entry->link;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user