cvs: php4 /ext/standard quot_print.c /ext/standard/tests/general_functions 002.phpt
| From: | Kirill Maximov | Date: | Fri, 17 Nov 2000 10:55:37 +0000 |
| Subject: | cvs: php4 /ext/standard quot_print.c /ext/standard/tests/general_functions 002.phpt | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-2654@lists.php.net to get a copy of this message | ||
kir Fri Nov 17 02:55:37 2000 EDT
Added files:
/php4/ext/standard/tests/general_functions 002.phpt
Modified files:
/php4/ext/standard quot_print.c
Log:
@ quoted_printable_decode() function is made RFC-2045 compliant. (Kir)
This hopefully closes bugs #5321, #7138, #7855.
Test script for the function is added.
Index: php4/ext/standard/quot_print.c
diff -u php4/ext/standard/quot_print.c:1.10 php4/ext/standard/quot_print.c:1.11
--- php4/ext/standard/quot_print.c:1.10 Sun Sep 3 02:31:25 2000
+++ php4/ext/standard/quot_print.c Fri Nov 17 02:55:37 2000
@@ -12,11 +12,11 @@
| 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> |
+----------------------------------------------------------------------+
*/
-/* $Id: quot_print.c,v 1.10 2000/09/03 09:31:25 stas Exp $ */
+/* $Id: quot_print.c,v 1.11 2000/11/17 10:55:37 kir Exp $ */
#include <stdlib.h>
@@ -61,7 +61,7 @@
{
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 @@
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';
Index: php4/ext/standard/tests/general_functions/002.phpt
+++ php4/ext/standard/tests/general_functions/002.phpt
--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ÁÐÕÝÅÎÎÙÅ
ÔÏÒÇÏ×ÙÅ ÐÒÏÅËÔÙ