php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Return to Bug #48482
Patch bug48482-2 revision 2014-12-28 19:50 UTC by kalle@php.net
Patch bug48482-doc revision 2014-12-27 18:33 UTC by kalle@php.net
Patch bug48482 revision 2014-12-27 18:27 UTC by kalle@php.net

Patch bug48482 for *General Issues Bug #48482

Patch version 2014-12-27 18:27 UTC

Return to Bug #48482 | Download this patch
This patch is obsolete

Obsoleted by patches:

Patch Revisions:

Developer: kalle@php.net

 Zend/zend_highlight.c             | 18 +++++++++++-------
 Zend/zend_highlight.h             |  5 +++--
 Zend/zend_ini_scanner.c           |  0
 Zend/zend_ini_scanner_defs.h      |  0
 Zend/zend_language_scanner.c      |  0
 Zend/zend_language_scanner_defs.h |  2 +-
 ext/standard/basic_functions.c    | 23 +++++++++++++++++------
 ext/standard/info.c               |  2 +-
 main/main.c                       |  3 ++-
 php.ini-development               |  4 ++++
 php.ini-production                |  4 ++++
 11 files changed, 43 insertions(+), 18 deletions(-)

diff --git a/Zend/zend_highlight.c b/Zend/zend_highlight.c
index 27e4fee..09c1254 100644
--- a/Zend/zend_highlight.c
+++ b/Zend/zend_highlight.c
@@ -26,11 +26,15 @@
 #include "zend_ptr_stack.h"
 #include "zend_globals.h"
 
-ZEND_API void zend_html_putc(char c)
+ZEND_API void zend_html_putc(char c, zend_syntax_highlighter_ini *syntax_highlighter_ini)
 {
 	switch (c) {
 		case '\n':
-			ZEND_PUTS("<br />");
+			if (syntax_highlighter_ini && !syntax_highlighter_ini->highlight_xhtml) {
+				ZEND_PUTS("<br>");
+			} else {
+				ZEND_PUTS("<br />");
+			}
 			break;
 		case '<':
 			ZEND_PUTS("&lt;");
@@ -54,7 +58,7 @@ ZEND_API void zend_html_putc(char c)
 }
 
 
-ZEND_API void zend_html_puts(const char *s, size_t len)
+ZEND_API void zend_html_puts(const char *s, size_t len, zend_syntax_highlighter_ini *syntax_highlighter_ini)
 {
 	const unsigned char *ptr = (const unsigned char*)s, *end = ptr + len;
 	unsigned char *filtered = NULL;
@@ -69,10 +73,10 @@ ZEND_API void zend_html_puts(const char *s, size_t len)
 	while (ptr<end) {
 		if (*ptr==' ') {
 			do {
-				zend_html_putc(*ptr);
+				zend_html_putc(*ptr, syntax_highlighter_ini);
 			} while ((++ptr < end) && (*ptr==' '));
 		} else {
-			zend_html_putc(*ptr++);
+			zend_html_putc(*ptr++, syntax_highlighter_ini);
 		}
 	}
 
@@ -121,7 +125,7 @@ ZEND_API void zend_highlight(zend_syntax_highlighter_ini *syntax_highlighter_ini
 				next_color = syntax_highlighter_ini->highlight_string;
 				break;
 			case T_WHITESPACE:
-				zend_html_puts((char*)LANG_SCNG(yy_text), LANG_SCNG(yy_leng));  /* no color needed */
+				zend_html_puts((char*)LANG_SCNG(yy_text), LANG_SCNG(yy_leng), syntax_highlighter_ini);  /* no color needed */
 				ZVAL_UNDEF(&token);
 				continue;
 				break;
@@ -144,7 +148,7 @@ ZEND_API void zend_highlight(zend_syntax_highlighter_ini *syntax_highlighter_ini
 			}
 		}
 
-		zend_html_puts((char*)LANG_SCNG(yy_text), LANG_SCNG(yy_leng));
+		zend_html_puts((char*)LANG_SCNG(yy_text), LANG_SCNG(yy_leng), syntax_highlighter_ini);
 
 		if (Z_TYPE(token) == IS_STRING) {
 			switch (token_type) {
diff --git a/Zend/zend_highlight.h b/Zend/zend_highlight.h
index 37bf654..80092a3 100644
--- a/Zend/zend_highlight.h
+++ b/Zend/zend_highlight.h
@@ -35,6 +35,7 @@ typedef struct _zend_syntax_highlighter_ini {
 	char *highlight_default;
 	char *highlight_string;
 	char *highlight_keyword;
+	zend_bool highlight_xhtml: 1;
 } zend_syntax_highlighter_ini;
 
 
@@ -43,8 +44,8 @@ ZEND_API void zend_highlight(zend_syntax_highlighter_ini *syntax_highlighter_ini
 ZEND_API void zend_strip(void);
 ZEND_API int highlight_file(char *filename, zend_syntax_highlighter_ini *syntax_highlighter_ini);
 ZEND_API int highlight_string(zval *str, zend_syntax_highlighter_ini *syntax_highlighter_ini, char *str_name);
-ZEND_API void zend_html_putc(char c);
-ZEND_API void zend_html_puts(const char *s, size_t len);
+ZEND_API void zend_html_putc(char c, zend_syntax_highlighter_ini *syntax_highlighter_ini);
+ZEND_API void zend_html_puts(const char *s, size_t len, zend_syntax_highlighter_ini *syntax_highlighter_ini);
 END_EXTERN_C()
 
 extern zend_syntax_highlighter_ini syntax_highlighter_ini;
diff --git a/Zend/zend_language_scanner_defs.h b/Zend/zend_language_scanner_defs.h
index baf859b..5926e3c 100644
--- a/Zend/zend_language_scanner_defs.h
+++ b/Zend/zend_language_scanner_defs.h
@@ -1,4 +1,4 @@
-/* Generated by re2c 0.13.7.5 */
+/* Generated by re2c 0.13.5 */
 #line 3 "Zend/zend_language_scanner_defs.h"
 
 enum YYCONDTYPE {
diff --git a/ext/standard/basic_functions.c b/ext/standard/basic_functions.c
index ed5206a..92f8ad0 100644
--- a/ext/standard/basic_functions.c
+++ b/ext/standard/basic_functions.c
@@ -717,6 +717,7 @@ ZEND_END_ARG_INFO()
 ZEND_BEGIN_ARG_INFO_EX(arginfo_highlight_file, 0, 0, 1)
 	ZEND_ARG_INFO(0, file_name)
 	ZEND_ARG_INFO(0, return)
+	ZEND_ARG_INFO(0, is_xhtml)
 ZEND_END_ARG_INFO()
 
 ZEND_BEGIN_ARG_INFO(arginfo_php_strip_whitespace, 0)
@@ -726,6 +727,7 @@ ZEND_END_ARG_INFO()
 ZEND_BEGIN_ARG_INFO_EX(arginfo_highlight_string, 0, 0, 1)
 	ZEND_ARG_INFO(0, string)
 	ZEND_ARG_INFO(0, return)
+	ZEND_ARG_INFO(0, is_xhtml)
 ZEND_END_ARG_INFO()
 
 ZEND_BEGIN_ARG_INFO(arginfo_ini_get, 0)
@@ -5067,19 +5069,20 @@ ZEND_API void php_get_highlight_struct(zend_syntax_highlighter_ini *syntax_highl
 	syntax_highlighter_ini->highlight_html    = INI_STR("highlight.html");
 	syntax_highlighter_ini->highlight_keyword = INI_STR("highlight.keyword");
 	syntax_highlighter_ini->highlight_string  = INI_STR("highlight.string");
+	syntax_highlighter_ini->highlight_xhtml	  = INI_BOOL("highlight.xhtml");
 }
 /* }}} */
 
-/* {{{ proto bool highlight_file(string file_name [, bool return] )
+/* {{{ proto bool highlight_file(string file_name [, bool return [, bool is_xhtml ]] )
    Syntax highlight a source file */
 PHP_FUNCTION(highlight_file)
 {
 	char *filename;
 	size_t filename_len, ret;
 	zend_syntax_highlighter_ini syntax_highlighter_ini;
-	zend_bool i = 0;
+	zend_bool i = 0, is_xhtml = 1;
 
-	if (zend_parse_parameters(ZEND_NUM_ARGS(), "p|b", &filename, &filename_len, &i) == FAILURE) {
+	if (zend_parse_parameters(ZEND_NUM_ARGS(), "p|bb", &filename, &filename_len, &i, &is_xhtml) == FAILURE) {
 		RETURN_FALSE;
 	}
 
@@ -5093,6 +5096,10 @@ PHP_FUNCTION(highlight_file)
 
 	php_get_highlight_struct(&syntax_highlighter_ini);
 
+	if (ZEND_NUM_ARGS() > 2) {
+		syntax_highlighter_ini.highlight_xhtml = is_xhtml;
+	}
+
 	ret = highlight_file(filename, &syntax_highlighter_ini);
 
 	if (ret == FAILURE) {
@@ -5147,17 +5154,17 @@ PHP_FUNCTION(php_strip_whitespace)
 }
 /* }}} */
 
-/* {{{ proto bool highlight_string(string string [, bool return] )
+/* {{{ proto bool highlight_string(string string [, bool return [, bool is_xhtml ]] )
    Syntax highlight a string or optionally return it */
 PHP_FUNCTION(highlight_string)
 {
 	zval *expr;
 	zend_syntax_highlighter_ini syntax_highlighter_ini;
 	char *hicompiled_string_description;
-	zend_bool i = 0;
+	zend_bool i = 0, is_xhtml = 1;
 	int old_error_reporting = EG(error_reporting);
 
-	if (zend_parse_parameters(ZEND_NUM_ARGS(), "z|b", &expr, &i) == FAILURE) {
+	if (zend_parse_parameters(ZEND_NUM_ARGS(), "z|bb", &expr, &i, &is_xhtml) == FAILURE) {
 		RETURN_FALSE;
 	}
 	convert_to_string_ex(expr);
@@ -5170,6 +5177,10 @@ PHP_FUNCTION(highlight_string)
 
 	php_get_highlight_struct(&syntax_highlighter_ini);
 
+	if (ZEND_NUM_ARGS() > 2) {
+		syntax_highlighter_ini.highlight_xhtml = is_xhtml;
+	}
+
 	hicompiled_string_description = zend_make_compiled_string_description("highlighted code");
 
 	if (highlight_string(expr, &syntax_highlighter_ini, hicompiled_string_description) == FAILURE) {
diff --git a/ext/standard/info.c b/ext/standard/info.c
index 71d09af..7f74e03 100644
--- a/ext/standard/info.c
+++ b/ext/standard/info.c
@@ -836,7 +836,7 @@ PHPAPI void php_print_info(int flag)
 		if (sapi_module.phpinfo_as_text) {
 			php_info_print(zend_version);
 		} else {
-			zend_html_puts(zend_version, strlen(zend_version));
+			php_html_puts(zend_version, strlen(zend_version));
 		}
 		php_info_print_box_end();
 		zend_string_free(php_uname);
diff --git a/main/main.c b/main/main.c
index 276058c..48abfab 100644
--- a/main/main.c
+++ b/main/main.c
@@ -527,6 +527,7 @@ PHP_INI_BEGIN()
 	PHP_INI_ENTRY_EX("highlight.html",			HL_HTML_COLOR,		PHP_INI_ALL,	NULL,			php_ini_color_displayer_cb)
 	PHP_INI_ENTRY_EX("highlight.keyword",		HL_KEYWORD_COLOR,	PHP_INI_ALL,	NULL,			php_ini_color_displayer_cb)
 	PHP_INI_ENTRY_EX("highlight.string",		HL_STRING_COLOR,	PHP_INI_ALL,	NULL,			php_ini_color_displayer_cb)
+	PHP_INI_ENTRY_EX("highlight.xhtml",			"1",				PHP_INI_ALL,	NULL,			php_ini_boolean_displayer_cb)
 
 	STD_PHP_INI_ENTRY_EX("display_errors",		"1",		PHP_INI_ALL,		OnUpdateDisplayErrors,	display_errors,			php_core_globals,	core_globals, display_errors_mode)
 	STD_PHP_INI_BOOLEAN("display_startup_errors",	"0",	PHP_INI_ALL,		OnUpdateBool,			display_startup_errors,	php_core_globals,	core_globals)
@@ -990,7 +991,7 @@ PHPAPI void php_win32_docref2_from_error(DWORD error, const char *param1, const
 /* {{{ php_html_puts */
 PHPAPI void php_html_puts(const char *str, size_t size)
 {
-	zend_html_puts(str, size);
+	zend_html_puts(str, size, NULL);
 }
 /* }}} */
 
diff --git a/php.ini-development b/php.ini-development
index c619678..56e80f1 100644
--- a/php.ini-development
+++ b/php.ini-development
@@ -312,6 +312,10 @@ disable_classes =
 ;highlight.default = #0000BB
 ;highlight.html    = #000000
 
+; Whether or not to enable XHTML formatted highlighted strings, setting this to 
+; Off will make highlighted strings HTML4/5 compatible
+;highlight.xhtml = On
+
 ; If enabled, the request will be allowed to complete even if the user aborts
 ; the request. Consider enabling it if executing long requests, which may end up
 ; being interrupted by the user or a browser timing out. PHP's default behavior
diff --git a/php.ini-production b/php.ini-production
index 1310f6c..cc55eee 100644
--- a/php.ini-production
+++ b/php.ini-production
@@ -312,6 +312,10 @@ disable_classes =
 ;highlight.default = #0000BB
 ;highlight.html    = #000000
 
+; Whether or not to enable XHTML formatted highlighted strings, setting this to 
+; Off will make highlighted strings HTML4/5 compatible
+;highlight.xhtml = On
+
 ; If enabled, the request will be allowed to complete even if the user aborts
 ; the request. Consider enabling it if executing long requests, which may end up
 ; being interrupted by the user or a browser timing out. PHP's default behavior
 
PHP Copyright © 2001-2019 The PHP Group
All rights reserved.
Last updated: Wed Aug 21 20:01:27 2019 UTC