]> granicus.if.org Git - php/commitdiff
MFPECL fix PECL Bug #14646: phar error message unclear with php stream wrappers ...
authorGreg Beaver <cellog@php.net>
Thu, 30 Apr 2009 04:43:10 +0000 (04:43 +0000)
committerGreg Beaver <cellog@php.net>
Thu, 30 Apr 2009 04:43:10 +0000 (04:43 +0000)
NEWS
ext/phar/phar.c
ext/phar/tests/phar_construct_invalidurl.phpt [new file with mode: 0644]

diff --git a/NEWS b/NEWS
index 6b9791bb5cc6b17d045216ca31310e6668c31c9a..01dd273b8e01949d3c7af85e3829e6b6bf91f5de 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -53,6 +53,8 @@ PHP                                                                        NEWS
   update). (Matteo)
 - Fixed bug #42362 (HTTP status codes 204 and 304 should not be gzipped).
   (Scott, Edward Z. Yang)
+- Fixed PECL bug #16338 (phar extension uses php_stream_copy_to_stream). (Greg)
+- Fixed PECL bug #14646 (phar error message unclear with php stream wrappers). (Greg)
 - Fixed an issue with ReflectionProperty::setAccessible().
   (Sebastian, Roman Borschel)
 
index 1035cc294aa27b30edaa73a41eb9e30c09d40096..df3d0997d75e219ff56da2f616f27f6161f8bed8 100644 (file)
@@ -1262,7 +1262,11 @@ int phar_open_or_create_filename(char *fname, int fname_len, char *alias, int al
        /* next try to create a new file */
        if (FAILURE == phar_detect_phar_fname_ext(fname, fname_len, &ext_str, &ext_len, !is_data, 1, 1 TSRMLS_CC)) {
                if (error) {
-                       spprintf(error, 0, "Cannot create phar '%s', file extension (or combination) not recognised", fname);
+                       if (ext_len == -2) {
+                               spprintf(error, 0, "Cannot create a phar archive from a URL like \"%s\".  Phar objects can only be created from local files", fname);
+                       } else {
+                               spprintf(error, 0, "Cannot create phar '%s', file extension (or combination) not recognised", fname);
+                       }
                }
                return FAILURE;
        }
@@ -1903,6 +1907,12 @@ int phar_detect_phar_fname_ext(const char *filename, int filename_len, const cha
        pos = memchr(filename, '/', filename_len);
 
        if (pos && pos != filename) {
+               /* check for url like http:// or phar:// */
+               if (*(pos - 1) == ':' && (pos - filename) < filename_len - 1 && *(pos + 1) == '/') {
+                       *ext_len = -2;
+                       *ext_str = NULL;
+                       return FAILURE;
+               }
                if (zend_hash_exists(&(PHAR_GLOBALS->phar_alias_map), (char *) filename, pos - filename)) {
                        *ext_str = pos;
                        *ext_len = -1;
diff --git a/ext/phar/tests/phar_construct_invalidurl.phpt b/ext/phar/tests/phar_construct_invalidurl.phpt
new file mode 100644 (file)
index 0000000..faac841
--- /dev/null
@@ -0,0 +1,30 @@
+--TEST--
+Phar object passed URL
+--INI--
+default_charset=UTF-8
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+--FILE--
+<?php
+try {
+       $a = new Phar('http://should.fail.com');
+} catch (UnexpectedValueException $e) {
+       echo $e->getMessage(),"\n";
+}
+try {
+       $a = new Phar('http://');
+} catch (UnexpectedValueException $e) {
+       echo $e->getMessage(),"\n";
+}
+try {
+       $a = new Phar('http:/');
+} catch (UnexpectedValueException $e) {
+       echo $e->getMessage(),"\n";
+}
+?>
+===DONE===
+--EXPECT--
+Cannot create a phar archive from a URL like "http://should.fail.com".  Phar objects can only be created from local files
+Cannot create a phar archive from a URL like "http://".  Phar objects can only be created from local files
+Cannot create phar 'http:/', file extension (or combination) not recognised
+===DONE===
\ No newline at end of file