Skip to content

Commit 809dabd

Browse files
committed
Merge branch 'xdebug_3_4'
* xdebug_3_4: Fixed issue #2365: INI settings error_prepend_string and error_append_string disregarded when a fatal error happens
2 parents 914cca1 + c931537 commit 809dabd

File tree

4 files changed

+119
-11
lines changed

4 files changed

+119
-11
lines changed

src/develop/stack.c

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -868,14 +868,11 @@ void xdebug_append_error_footer(xdebug_str *str, int html)
868868

869869
char *xdebug_get_printable_stack(int html, int error_type, const char *buffer, const char *error_filename, const int error_lineno, int include_decription)
870870
{
871-
char *prepend_string;
872-
char *append_string;
873-
char *error_type_str = xdebug_error_type(error_type);
874-
char *error_type_str_simple = xdebug_error_type_simple(error_type);
875-
xdebug_str str = XDEBUG_STR_INITIALIZER;
876-
877-
prepend_string = INI_STR((char*) "error_prepend_string");
878-
append_string = INI_STR((char*) "error_append_string");
871+
char *error_type_str = xdebug_error_type(error_type);
872+
char *error_type_str_simple = xdebug_error_type_simple(error_type);
873+
xdebug_str str = XDEBUG_STR_INITIALIZER;
874+
char *prepend_string = INI_STR((char*) "error_prepend_string");
875+
char *append_string = INI_STR((char*) "error_append_string");
879876

880877
if (prepend_string) {
881878
xdebug_str_add(&str, prepend_string, 0);
@@ -941,16 +938,23 @@ static char *xdebug_handle_stack_trace(int type, char *error_type_str, const cha
941938

942939
/* We need to see if we have an uncaught exception fatal error now */
943940
if (type == E_ERROR && ((tmp_buf = xdebug_strip_php_stack_trace(buffer)) != NULL)) {
944-
xdebug_str str = XDEBUG_STR_INITIALIZER;
941+
xdebug_str str = XDEBUG_STR_INITIALIZER;
942+
char *prepend_string = INI_STR((char*) "error_prepend_string");
943+
char *append_string = INI_STR((char*) "error_append_string");
945944

946-
/* Append error */
945+
if (prepend_string) {
946+
xdebug_str_add(&str, prepend_string, 0);
947+
}
947948
xdebug_append_error_head(&str, PG(html_errors), "uncaught-exception");
948949
xdebug_append_error_description(&str, PG(html_errors), error_type_str, tmp_buf, error_filename, error_lineno);
949950
xdebug_append_printable_stack(&str, PG(html_errors));
950951
if (XG_BASE(last_exception_trace)) {
951952
xdebug_str_add(&str, XG_BASE(last_exception_trace), 0);
952953
}
953954
xdebug_append_error_footer(&str, PG(html_errors));
955+
if (append_string) {
956+
xdebug_str_add(&str, append_string, 0);
957+
}
954958

955959
free(tmp_buf);
956960
printable_stack = str.d;
@@ -1195,7 +1199,6 @@ void xdebug_develop_throw_exception_hook(zend_object *exception, zval *file, zva
11951199
zend_class_entry *exception_ce = exception->ce;
11961200
char *exception_trace;
11971201
xdebug_str tmp_str = XDEBUG_STR_INITIALIZER;
1198-
11991202
zval *z_previous_exception, *z_last_exception_slot, *z_previous_trace;
12001203
zend_object *previous_exception_obj = exception;
12011204
zval dummy;
@@ -1265,9 +1268,18 @@ void xdebug_develop_throw_exception_hook(zend_object *exception, zval *file, zva
12651268
}
12661269
if (PG(display_errors)) {
12671270
xdebug_str displ_tmp_str = XDEBUG_STR_INITIALIZER;
1271+
char *prepend_string = INI_STR((char*) "error_prepend_string");
1272+
char *append_string = INI_STR((char*) "error_append_string");
1273+
1274+
if (prepend_string) {
1275+
xdebug_str_add(&displ_tmp_str, prepend_string, 0);
1276+
}
12681277
xdebug_append_error_head(&displ_tmp_str, PG(html_errors), "exception");
12691278
xdebug_str_add(&displ_tmp_str, exception_trace, 0);
12701279
xdebug_append_error_footer(&displ_tmp_str, PG(html_errors));
1280+
if (append_string) {
1281+
xdebug_str_add(&displ_tmp_str, append_string, 0);
1282+
}
12711283

12721284
php_printf("%s", displ_tmp_str.d);
12731285
xdebug_str_destroy(&displ_tmp_str);

tests/develop/bug02365-001.phpt

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
--TEST--
2+
Test for bug #2365: INI settings error_prepend_string and error_append_string disregarded when a fatal error happens (text)
3+
--INI--
4+
xdebug.mode=develop
5+
error_prepend_string="<!-- PREPEND_ERROR_STRING -->"
6+
error_append_string="<!-- APPEND_ERROR_STRING -->"
7+
--FILE--
8+
<?php
9+
$a = $undefinedVar;
10+
echo "\n\n\n";
11+
new NotAClass();
12+
?>
13+
--EXPECTF--
14+
<!-- PREPEND_ERROR_STRING -->
15+
Warning: Undefined variable $undefinedVar in %sbug02365-001.php on line 2
16+
17+
Call Stack:
18+
%w%f %w%d 1. {main}() %sbug02365-001.php:0
19+
20+
<!-- APPEND_ERROR_STRING -->
21+
22+
23+
<!-- PREPEND_ERROR_STRING -->
24+
Fatal error: Uncaught Error: Class "NotAClass" not found in %sbug02365-001.php on line 4
25+
26+
Error: Class "NotAClass" not found in %sbug02365-001.php on line 4
27+
28+
Call Stack:
29+
%w%f %w%d 1. {main}() %sbug02365-001.php:0
30+
31+
<!-- APPEND_ERROR_STRING -->

tests/develop/bug02365-002.phpt

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
--TEST--
2+
Test for bug #2365: INI settings error_prepend_string and error_append_string disregarded when a fatal error happens (ansi)
3+
--INI--
4+
xdebug.mode=develop
5+
xdebug.cli_color=2
6+
error_prepend_string="<!-- PREPEND_ERROR_STRING -->"
7+
error_append_string="<!-- APPEND_ERROR_STRING -->"
8+
--FILE--
9+
<?php
10+
$a = $undefinedVar;
11+
echo "\n\n\n";
12+
new NotAClass();
13+
?>
14+
--EXPECTF--
15+
<!-- PREPEND_ERROR_STRING -->
16+
Warning: Undefined variable $undefinedVar in %sbug02365-002.php on line 2
17+
18+
Call Stack:
19+
%w%f %w%d 1. {main}() %sbug02365-002.php:0
20+
21+
<!-- APPEND_ERROR_STRING -->
22+
23+
24+
<!-- PREPEND_ERROR_STRING -->
25+
Fatal error: Uncaught Error: Class "NotAClass" not found in %sbug02365-002.php on line 4
26+
27+
Error: Class "NotAClass" not found in %sbug02365-002.php on line 4
28+
29+
Call Stack:
30+
%w%f %w%d 1. {main}() %sbug02365-002.php:0
31+
32+
<!-- APPEND_ERROR_STRING -->

tests/develop/bug02365-003.phpt

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
--TEST--
2+
Test for bug #2365: INI settings error_prepend_string and error_append_string disregarded when a fatal error happens (HTML)
3+
--INI--
4+
xdebug.mode=develop
5+
html_errors=1
6+
error_prepend_string="<!-- PREPEND_ERROR_STRING -->"
7+
error_append_string="<!-- APPEND_ERROR_STRING -->"
8+
--FILE--
9+
<?php
10+
$a = $undefinedVar;
11+
echo "\n\n\n";
12+
new NotAClass();
13+
?>
14+
--EXPECTF--
15+
<!-- PREPEND_ERROR_STRING --><br />
16+
<font size='1'><table class='xdebug-error xe-warning' dir='ltr' border='1' cellspacing='0' cellpadding='1'>
17+
<tr><th align='left' bgcolor='#f57900' colspan="5"><span style='background-color: #cc0000; color: #fce94f; font-size: x-large;'>( ! )</span> Warning: Undefined variable $undefinedVar in %sbug02365-003.php on line <i>2</i></th></tr>
18+
<tr><th align='left' bgcolor='#e9b96e' colspan='5'>Call Stack</th></tr>
19+
<tr><th align='center' bgcolor='#eeeeec'>#</th><th align='left' bgcolor='#eeeeec'>Time</th><th align='left' bgcolor='#eeeeec'>Memory</th><th align='left' bgcolor='#eeeeec'>Function</th><th align='left' bgcolor='#eeeeec'>Location</th></tr>
20+
<tr><td bgcolor='#eeeeec' align='center'>1</td><td bgcolor='#eeeeec' align='center'>%f</td><td bgcolor='#eeeeec' align='right'>%d</td><td bgcolor='#eeeeec'>{main}( )</td><td title='%sbug02365-003.php' bgcolor='#eeeeec'>%sbug02365-003.php<b>:</b>0</td></tr>
21+
</table></font>
22+
<!-- APPEND_ERROR_STRING -->
23+
24+
25+
<!-- PREPEND_ERROR_STRING --><br />
26+
<font size='1'><table class='xdebug-error xe-uncaught-exception' dir='ltr' border='1' cellspacing='0' cellpadding='1'>
27+
<tr><th align='left' bgcolor='#f57900' colspan="5"><span style='background-color: #cc0000; color: #fce94f; font-size: x-large;'>( ! )</span> Fatal error: Uncaught Error: Class "NotAClass" not found in %sbug02365-003.php on line <i>4</i></th></tr>
28+
<tr><th align='left' bgcolor='#f57900' colspan="5"><span style='background-color: #cc0000; color: #fce94f; font-size: x-large;'>( ! )</span> Error: Class "NotAClass" not found in %sbug02365-003.php on line <i>4</i></th></tr>
29+
<tr><th align='left' bgcolor='#e9b96e' colspan='5'>Call Stack</th></tr>
30+
<tr><th align='center' bgcolor='#eeeeec'>#</th><th align='left' bgcolor='#eeeeec'>Time</th><th align='left' bgcolor='#eeeeec'>Memory</th><th align='left' bgcolor='#eeeeec'>Function</th><th align='left' bgcolor='#eeeeec'>Location</th></tr>
31+
<tr><td bgcolor='#eeeeec' align='center'>1</td><td bgcolor='#eeeeec' align='center'>%f</td><td bgcolor='#eeeeec' align='right'>%d</td><td bgcolor='#eeeeec'>{main}( )</td><td title='%sbug02365-003.php' bgcolor='#eeeeec'>%sbug02365-003.php<b>:</b>0</td></tr>
32+
</table></font>
33+
<!-- APPEND_ERROR_STRING -->

0 commit comments

Comments
 (0)