]> granicus.if.org Git - php/commitdiff
- Fixed magic file regex support
authorFelipe Pena <felipensp@gmail.com>
Thu, 24 May 2012 16:42:47 +0000 (13:42 -0300)
committerFelipe Pena <felipensp@gmail.com>
Thu, 24 May 2012 16:42:47 +0000 (13:42 -0300)
ext/fileinfo/libmagic/softmagic.c
ext/fileinfo/tests/finfo_file_002.phpt
ext/fileinfo/tests/finfo_file_regex.phpt [new file with mode: 0644]
ext/fileinfo/tests/resources/test.awk [new file with mode: 0644]

index 648f641697fef50372c3810c1d97bf00eb58e305..f9c2836dd26bacc9e8e26f8938eabae7f47ce3e5 100644 (file)
@@ -1654,29 +1654,6 @@ convert_libmagic_pattern(zval *pattern, int options)
                
                for (i=0; i<Z_STRLEN_P(pattern); i++, j++) {
                        switch (Z_STRVAL_P(pattern)[i]) {
-                               case '?':
-                                       t[j] = '.';
-                                       break;
-                               case '*':
-                                       t[j++] = '.';
-                                       t[j] = '*';
-                                       break;
-                               case '.':
-                                       t[j++] = '\\';
-                                       t[j] = '.';
-                                       break;
-                               case '\\':
-                                       t[j++] = '\\';
-                                       t[j] = '\\';
-                                       break;
-                               case '(':
-                                       t[j++] = '\\';
-                                       t[j] = '(';
-                                       break;
-                               case ')':
-                                       t[j++] = '\\';
-                                       t[j] = ')';
-                                       break;
                                case '~':
                                        t[j++] = '\\';
                                        t[j] = '~';
@@ -1873,7 +1850,7 @@ magiccheck(struct magic_set *ms, struct magic *m)
                
                convert_libmagic_pattern(pattern, options);
                
-               l = 0;
+               l = v = 0;
 #if (PHP_MAJOR_VERSION < 6)
                if ((pce = pcre_get_compiled_regex_cache(Z_STRVAL_P(pattern), Z_STRLEN_P(pattern) TSRMLS_CC)) == NULL) {
 #else
index 9ed19a9762eea23dc5c576a9a85ba916f0d2de32..3593233c3996c3381b80e1cc26de642333116e0a 100644 (file)
@@ -18,9 +18,11 @@ ksort($results);
 var_dump($results);
 ?>
 --EXPECTF--
-array(6) {
+array(7) {
   ["%s/resources/dir.zip"]=>
   string(15) "application/zip"
+  ["%s/resources/test.awk"]=>
+  string(10) "text/plain"
   ["%s/resources/test.bmp"]=>
   string(14) "image/x-ms-bmp"
   ["%s/resources/test.gif"]=>
diff --git a/ext/fileinfo/tests/finfo_file_regex.phpt b/ext/fileinfo/tests/finfo_file_regex.phpt
new file mode 100644 (file)
index 0000000..c1cc36f
--- /dev/null
@@ -0,0 +1,28 @@
+--TEST--
+Test finfo_file() function : regex rules
+--SKIPIF--
+<?php require_once(dirname(__FILE__) . '/skipif.inc'); ?>
+--FILE--
+<?php
+/**
+ * Works with the unix file command:
+ * $ file -m magic resources/test.awk
+ * resources/test.awk: awk script, ASCII text
+ */
+$magicFile = dirname(__FILE__) . DIRECTORY_SEPARATOR . 'magic';
+$finfo = finfo_open( FILEINFO_MIME, $magicFile );
+
+echo "*** Testing finfo_file() : regex rules ***\n";
+
+// Calling finfo_file() with all possible arguments
+$file = __DIR__ . '/resources/test.awk';
+var_dump( finfo_file( $finfo, $file ) );
+var_dump( finfo_file( $finfo, $file, FILEINFO_CONTINUE ) );
+
+?>
+===DONE===
+--EXPECTF--
+*** Testing finfo_file() : regex rules ***
+string(28) "text/plain; charset=us-ascii"
+string(22) "awk script, ASCII text"
+===DONE===
diff --git a/ext/fileinfo/tests/resources/test.awk b/ext/fileinfo/tests/resources/test.awk
new file mode 100644 (file)
index 0000000..e000d50
--- /dev/null
@@ -0,0 +1 @@
+BEGIN { print "START" }