summaryrefslogtreecommitdiff
path: root/ext
diff options
context:
space:
mode:
authorKirill Maximov <kir@php.net>2000-11-17 10:55:37 +0000
committerKirill Maximov <kir@php.net>2000-11-17 10:55:37 +0000
commit023a95ae1c9f015d064eb35a370659da6ba25222 (patch)
tree5006b0c177fafad67629c5375b11b64553f8b3b6 /ext
parent86f0184c335205c2a7b6b0145690cacc28969937 (diff)
downloadphp-git-023a95ae1c9f015d064eb35a370659da6ba25222.tar.gz
@ quoted_printable_decode() function is made RFC-2045 compliant. (Kir)
This hopefully closes bugs #5321, #7138, #7855. Test script for the function is added.
Diffstat (limited to 'ext')
-rw-r--r--ext/standard/quot_print.c63
-rw-r--r--ext/standard/tests/general_functions/002.phpt13
2 files changed, 57 insertions, 19 deletions
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 <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
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--
+<?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