PHP 4.0 Bug #5321: quoted_printable_decode not decoding properly

From: Date: Sat, 01 Jul 2000 22:20:47 +0000
Subject: PHP 4.0 Bug #5321: quoted_printable_decode not decoding properly
Groups: php.dev 
Request: Send a blank email to php-dev+get-23093@lists.php.net to get a copy of this message
From: mcp@abrax.net Operating system: redhat 6.1 PHP version: 4.0.1pl2 PHP Bug Type: Misbehaving function Bug description: quoted_printable_decode not decoding properly The following code will produce the correct results (with a probable speed increase). /* * * Decoding Quoted-printable string. * *** modified 2000.06.30 by Mark Peters *** fixed code to recognize '= cr lf' sequence as soft newline *** and ignore (hide) mis-formed or bogus escape sequences */ /* {{{ proto string quoted_printable_decode(string str) Convert a quoted-printable string to an 8 bit string */ PHP_FUNCTION(quoted_printable_decode) { pval **arg1; char *str; int i = 0, j = 0; if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1,&arg1)==FAILURE) { WRONG_PARAM_COUNT; } convert_to_string_ex(arg1); str = (*arg1)->value.str.val; while ( str[i] ) { if (str[i] == '=') // start of escape sequence { // look for soft line break sequence ( = cr lf ) if (str[i+1] == 13 && str[i+2] == 10) { i += 3; // skip over crlf sequence continue; } // first digit not hex? if (!isxdigit((int)str[i+1])) { ++i; continue; } // second digit not hex? if (!isxdigit((int)str[i+2])) { i += 2; continue; } // good escape code str[j++] = (php_hex2int((int)str[i+1]) << 4 ) + php_hex2int((int)str[i+2]); i += 3; continue; } str[j++] = str[i++]; } str[j] = '\0'; RETVAL_STRINGL(str, j, 1) }

« previous php.dev (#23093) next »