From 023a95ae1c9f015d064eb35a370659da6ba25222 Mon Sep 17 00:00:00 2001 From: Kirill Maximov Date: Fri, 17 Nov 2000 10:55:37 +0000 Subject: [PATCH] @ quoted_printable_decode() function is made RFC-2045 compliant. (Kir) This hopefully closes bugs #5321, #7138, #7855. Test script for the function is added. --- ext/standard/quot_print.c | 63 +++++++++++++------ ext/standard/tests/general_functions/002.phpt | 13 ++++ 2 files changed, 57 insertions(+), 19 deletions(-) create mode 100644 ext/standard/tests/general_functions/002.phpt diff --git a/ext/standard/quot_print.c b/ext/standard/quot_print.c index aec0c98775..4e3b1219c3 100644 --- a/ext/standard/quot_print.c +++ b/ext/standard/quot_print.c @@ -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 | + | Authors: Kirill Maximov | +----------------------------------------------------------------------+ */ @@ -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 index 0000000000..d78bdb9afa --- /dev/null +++ b/ext/standard/tests/general_functions/002.phpt @@ -0,0 +1,13 @@ +--TEST-- +quoted_printable_decode() function test +--POST-- +--GET-- +--FILE-- + +--EXPECT-- +úwow-factorÁÐÕÝÅÎÎÙÅ + ÔÏÒÇÏ×ÙÅ ÐÒÏÅËÔÙ \ No newline at end of file -- 2.40.0