com php-src: Use nicer output for characters < 32 and > 126 in exception strings Using question marks might confuse more than it helps. Users are
wondering what happened to their string...: Zend/zend_excepti ons.c

From: Date: Thu, 20 Feb 2014 16:39:58 +0000
Subject: com php-src: Use nicer output for characters < 32 and > 126 in exception strings Using question marks might confuse more than it helps. Users are
wondering what happened to their string...: Zend/zend_excepti ons.c
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-76133@lists.php.net to get a copy of this message
Commit: afa03a470ef90a53f2b59a8175f77afdb6b5a651 Author: Bob Weinand <bobwei9@hotmail.com> Thu, 20 Feb 2014 17:39:58 +0100 Parents: 633f898f1520253d3530fe91fc82f68bca7c4627 Branches: PHP-5.4 Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=afa03a470ef90a53f2b59a8175f77afdb6b5a651 Log: Use nicer output for characters < 32 and > 126 in exception strings Using question marks might confuse more than it helps. Users are wondering what happened to their string... Changed paths: M Zend/zend_exceptions.c Diff: diff --git a/Zend/zend_exceptions.c b/Zend/zend_exceptions.c index 2ef74ad..ced1ebf 100644 --- a/Zend/zend_exceptions.c +++ b/Zend/zend_exceptions.c @@ -360,6 +360,11 @@ ZEND_METHOD(error_exception, getSeverity) } \ } + +#define TRACE_ARG_APPEND(vallen) \ + *str = (char*)erealloc(*str, *len + 1 + vallen); \ + memcpy((*str) + *len - l_added + 1 + vallen, (*str) + *len - l_added + 1, l_added); + /* }}} */ static int _build_trace_args(zval **arg TSRMLS_DC, int num_args, va_list args, zend_hash_key *hash_key) /* {{{ */ @@ -371,7 +376,7 @@ static int _build_trace_args(zval **arg TSRMLS_DC, int num_args, va_list args, z len = va_arg(args, int*); /* the trivial way would be to do: - * conver_to_string_ex(arg); + * convert_to_string_ex(arg); * append it and kill the now tmp arg. * but that could cause some E_NOTICE and also damn long lines. */ @@ -394,8 +399,58 @@ static int _build_trace_args(zval **arg TSRMLS_DC, int num_args, va_list args, z l_added += 3 + 1; } while (--l_added) { - if ((*str)[*len - l_added] < 32) { - (*str)[*len - l_added] = '?'; + unsigned char chr = (*str)[*len - l_added]; + if (chr < 32 || chr == '\\' || chr > 126) { + (*str)[*len - l_added] = '\\'; + + switch (chr) { + case '\n': + TRACE_ARG_APPEND(1); + (*str)[++(*len) - l_added] = 'n'; + break; + case '\r': + TRACE_ARG_APPEND(1); + (*str)[++(*len) - l_added] = 'r'; + break; + case '\t': + TRACE_ARG_APPEND(1); + (*str)[++(*len) - l_added] = 't'; + break; + case '\f': + TRACE_ARG_APPEND(1); + (*str)[++(*len) - l_added] = 'f'; + break; + case '\v': + TRACE_ARG_APPEND(1); + (*str)[++(*len) - l_added] = 'v'; + break; +#ifndef PHP_WIN32 + case '\e': +#else + case VK_ESCAPE: +#endif + TRACE_ARG_APPEND(1); + (*str)[++(*len) - l_added] = 'e'; + break; + case '\\': + TRACE_ARG_APPEND(1); + (*str)[++(*len) - l_added] = '\\'; + break; + default: + TRACE_ARG_APPEND(3); + (*str)[*len - l_added + 1] = 'x'; + if ((chr >> 4) < 10) { + (*str)[*len - l_added + 2] = (chr >> 4) + '0'; + } else { + (*str)[*len - l_added + 2] = (chr >> 4) + 'A' - 10; + } + if (chr % 16 < 10) { + (*str)[*len - l_added + 3] = chr % 16 + '0'; + } else { + (*str)[*len - l_added + 3] = chr % 16 + 'A' - 10; + } + *len += 3; + } } } break;

« previous php.cvs (#76133) next »