]> granicus.if.org Git - php/commitdiff
@ quoted_printable_decode() function is made RFC-2045 compliant. (Kir)
authorKirill Maximov <kir@php.net>
Fri, 17 Nov 2000 10:55:37 +0000 (10:55 +0000)
committerKirill Maximov <kir@php.net>
Fri, 17 Nov 2000 10:55:37 +0000 (10:55 +0000)
  This hopefully closes bugs #5321, #7138, #7855.
  Test script for the function is added.

ext/standard/quot_print.c
ext/standard/tests/general_functions/002.phpt [new file with mode: 0644]

index aec0c9877541a17eadff1c8ee46bac4237cc776d..4e3b1219c3b2484eb0118f12e2a10de10a9af704 100644 (file)
@@ -12,7 +12,7 @@
    | obtain it through the world-wide-web, please send a note to          |
    | license@php.net so we can mail you a copy immediately.               |
    +----------------------------------------------------------------------+
-   | Authors: Kirill Maximov <kir@rus.net>                                |
+   | Authors: Kirill Maximov <kir@actimind.com>                                |
    +----------------------------------------------------------------------+
  */
 
@@ -61,7 +61,7 @@ PHP_FUNCTION(quoted_printable_decode)
 {
        pval **arg1;
        char *str_in, *str_out;
-       int i = 0, j = 0;
+       int i = 0, j = 0, k;
        
     if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1,&arg1)==FAILURE) 
     {
@@ -78,24 +78,49 @@ PHP_FUNCTION(quoted_printable_decode)
        str_out = emalloc((*arg1)->value.str.len+1);
     while ( str_in[i] )
     {
-       if ( (str_in[i] == '=') && str_in[i+1] && str_in[i+2] &&
-            ( isdigit((int)str_in[i+1]) || (str_in[i+1]<='F' && str_in[i+1]>='A'))
-            &&
-            ( isdigit((int)str_in[i+2]) || (str_in[i+2]<='F' && str_in[i+2]>='A'))
-          )
-       {
-               str_out[j++] = (php_hex2int((int)str_in[i+1]) << 4 ) 
-                          + php_hex2int((int)str_in[i+2]);
-               i += 3;
-       }
-       else if ( str_in[i] == 13 )
-       {
-               i++;
-       }
-       else
-       {       
+        switch (str_in[i])
+        {
+        case '=':
+            if (str_in[i+1] && str_in[i+2] && 
+                isxdigit((int)str_in[i+1]) && 
+                isxdigit((int)str_in[i+1]) )
+            {
+                str_out[j++] = (php_hex2int((int)str_in[i+1]) << 4 ) 
+                           + php_hex2int((int)str_in[i+2]);
+                i += 3;
+            }
+            else   /* check for soft line break according to RFC 2045*/
+            {
+                k = 1;
+                while ( str_in[i+k] && ((str_in[i+k] == 32) || (str_in[i+k] == 9)) ) 
+                {
+                   /* Possibly, skip spaces/tabs at the end of line */
+                    k++;
+                }
+                if (!str_in[i+k])
+                {
+                    /* End of line reached */
+                    i += k;
+                }
+                else if ( (str_in[i+k] == 10) && (str_in[i+k+1] == 13))
+                {
+                    /* CRLF */
+                    i += k+2;
+                }
+                else if ( (str_in[i+k] == 13) || (str_in[i+k] == 10) )
+                {
+                    /* CR or LF */
+                    i += k+1;
+                }
+                else
+                {
+                       str_out[j++] = str_in[i++];
+                }
+            }
+            break;
+        default:
                str_out[j++] = str_in[i++];
-       }
+        }
     }
     str_out[j] = '\0';
     
diff --git a/ext/standard/tests/general_functions/002.phpt b/ext/standard/tests/general_functions/002.phpt
new file mode 100644 (file)
index 0000000..d78bdb9
--- /dev/null
@@ -0,0 +1,13 @@
+--TEST--
+quoted_printable_decode() function test
+--POST--
+--GET--
+--FILE--
+<?php echo quoted_printable_decode("=FAwow-factor=C1=D0=D5=DD=C5=CE=CE=D9=C5=0A=        
+=20=D4=CF=D2=C7=CF=D7=D9=C5=       
+=20=           
+=D0=
+=D2=CF=C5=CB=D4=D9"); ?>
+--EXPECT--
+úwow-factorÁÐÕÝÅÎÎÙÅ
+ ÔÏÒÇÏ×ÙÅ ÐÒÏÅËÔÙ
\ No newline at end of file