summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGreg Beaver <cellog@php.net>2008-05-11 23:03:56 +0000
committerGreg Beaver <cellog@php.net>2008-05-11 23:03:56 +0000
commit24efbb759b781795a4fc3af7c0a19d19704cbbd4 (patch)
treeba4710fed6af8be6492c5edb043eb0dc84a48ab6
parent70d0a4c0456f4c53856e28963dd2275385589454 (diff)
downloadphp-git-24efbb759b781795a4fc3af7c0a19d19704cbbd4.tar.gz
simplify phar_get_link_location and increase its coverage to 100%
-rw-r--r--ext/phar/tests/tar/files/tinylink.tarbin0 -> 10240 bytes
-rw-r--r--ext/phar/tests/tar/links4.phpt19
-rw-r--r--ext/phar/util.c9
3 files changed, 22 insertions, 6 deletions
diff --git a/ext/phar/tests/tar/files/tinylink.tar b/ext/phar/tests/tar/files/tinylink.tar
new file mode 100644
index 0000000000..741b56c2f5
--- /dev/null
+++ b/ext/phar/tests/tar/files/tinylink.tar
Binary files differ
diff --git a/ext/phar/tests/tar/links4.phpt b/ext/phar/tests/tar/links4.phpt
new file mode 100644
index 0000000000..d0783e84ac
--- /dev/null
+++ b/ext/phar/tests/tar/links4.phpt
@@ -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===
diff --git a/ext/phar/util.c b/ext/phar/util.c
index 09258b1f96..0add3b913e 100644
--- a/ext/phar/util.c
+++ b/ext/phar/util.c
@@ -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;
}