From a769454d79121a753ce92e5a0a60a8893189c968 Mon Sep 17 00:00:00 2001 From: Sascha Schumann Date: Sun, 12 May 2002 14:48:22 +0000 Subject: [PATCH] reenable php_html_puts --- ext/standard/info.c | 13 ++++++------ main/main.c | 48 ++++++++++++++++++++++++++++++++++++++++++--- main/php_ini.c | 2 +- main/php_main.h | 2 ++ 4 files changed, 55 insertions(+), 10 deletions(-) diff --git a/ext/standard/info.c b/ext/standard/info.c index 8b8c7d7a1a..24dec62483 100644 --- a/ext/standard/info.c +++ b/ext/standard/info.c @@ -67,6 +67,7 @@ static void php_print_gpcse_array(char *name, uint name_length TSRMLS_DC) { zval **data, **tmp, tmp2; char *string_key; + uint string_len; ulong num_key; if (zend_hash_find(&EG(symbol_table), name, name_length+1, (void **) &data)!=FAILURE @@ -77,9 +78,9 @@ static void php_print_gpcse_array(char *name, uint name_length TSRMLS_DC) PUTS(""); PUTS(name); PUTS("[\""); - switch (zend_hash_get_current_key(Z_ARRVAL_PP(data), &string_key, &num_key, 0)) { + switch (zend_hash_get_current_key_ex(Z_ARRVAL_PP(data), &string_key, &string_len, &num_key, 0, NULL)) { case HASH_KEY_IS_STRING: - zend_html_puts(string_key, strlen(string_key)); + php_html_puts(string_key, strlen(string_key) TSRMLS_CC); break; case HASH_KEY_IS_LONG: php_printf("%ld", num_key); @@ -94,10 +95,10 @@ static void php_print_gpcse_array(char *name, uint name_length TSRMLS_DC) tmp2 = **tmp; zval_copy_ctor(&tmp2); convert_to_string(&tmp2); - zend_html_puts(Z_STRVAL(tmp2), Z_STRLEN(tmp2)); + php_html_puts(Z_STRVAL(tmp2), Z_STRLEN(tmp2) TSRMLS_CC); zval_dtor(&tmp2); } else { - zend_html_puts(Z_STRVAL_PP(tmp), Z_STRLEN_PP(tmp)); + php_html_puts(Z_STRVAL_PP(tmp), Z_STRLEN_PP(tmp) TSRMLS_CC); } PUTS(" \n"); zend_hash_move_forward(Z_ARRVAL_PP(data)); @@ -290,7 +291,7 @@ PHPAPI void php_print_info(int flag TSRMLS_DC) PUTS("?="ZEND_LOGO_GUID"\" border=\"0\" align=\"right\" alt=\"Zend logo\">\n"); } php_printf("This program makes use of the Zend Scripting Language Engine:
"); - zend_html_puts(zend_version, strlen(zend_version)); + php_html_puts(zend_version, strlen(zend_version) TSRMLS_CC); php_info_print_box_end(); efree(php_uname); } @@ -482,7 +483,7 @@ PHPAPI void php_info_print_table_row(int num_cols, ...) if (!row_element || !*row_element) { php_printf(" "); } else { - zend_html_puts(row_element, strlen(row_element)); + php_html_puts(row_element, strlen(row_element) TSRMLS_CC); } php_printf("%s", (i==0?"
":"")); diff --git a/main/main.c b/main/main.c index 96411157ba..26c21068b8 100644 --- a/main/main.c +++ b/main/main.c @@ -377,12 +377,54 @@ PHPAPI int php_printf(const char *format, ...) } /* }}} */ - /* {{{ php_html_puts */ -/* wrapper for backwards compatibility */ +#include "ext/standard/php_smart_str.h" + PHPAPI void php_html_puts(const char *str, uint size TSRMLS_DC) { - zend_html_puts(str, size); + const char *end = str+size; + const char *p = str; + smart_str s = {0}; + + while (p < end) { + switch (*p) { + case '\n': + smart_str_appendl(&s, "
", sizeof("
")-1); + break; + case '<': + smart_str_appendl(&s, "<", sizeof("<")-1); + break; + case '>': + smart_str_appendl(&s, ">", sizeof(">")-1); + break; + case '&': + smart_str_appendl(&s, "&", sizeof("&")-1); + break; + case ' ': { + const char *nextchar = p+1, *prevchar = p-1; + + /* series of spaces should be converted to  's */ + if (((nextchar < end) && *nextchar==' ') + || ((prevchar >= str) && *prevchar==' ')) { + smart_str_appendl(&s, " ", sizeof(" ")-1); + } else { + smart_str_appendc(&s, ' '); + } + } + break; + case '\t': + smart_str_appendl(&s, "    ", sizeof("    ")-1); + break; + default: + smart_str_appendc(&s, *p); + } + p++; + } + + if (s.c) { + PHPWRITE(s.c, s.len); + smart_str_free(&s); + } } /* }}} */ diff --git a/main/php_ini.c b/main/php_ini.c index 6610775a68..78d7023f94 100644 --- a/main/php_ini.c +++ b/main/php_ini.c @@ -74,7 +74,7 @@ static void php_ini_displayer_cb(zend_ini_entry *ini_entry, int type) display_string_length = sizeof("no value")-1; } if(esc_html) { - zend_html_puts(display_string, display_string_length); + php_html_puts(display_string, display_string_length TSRMLS_CC); } else { PHPWRITE(display_string, display_string_length); } diff --git a/main/php_main.h b/main/php_main.h index ea9137c5f8..0ae80136cd 100644 --- a/main/php_main.h +++ b/main/php_main.h @@ -45,6 +45,8 @@ PHPAPI int php_lint_script(zend_file_handle *file TSRMLS_DC); PHPAPI void php_handle_aborted_connection(void); PHPAPI int php_handle_auth_data(const char *auth TSRMLS_DC); +PHPAPI void php_html_puts(const char *str, uint siz TSRMLS_DC); + extern void php_call_shutdown_functions(void); /* environment module */ -- 2.40.0