Skip to content

Commit 85f62ca

Browse files
author
Andrei Zmievski
committed
Do not show exception message if it's empty.
# Is there a way to preserve the case of the exception class here?
1 parent 0eead36 commit 85f62ca

File tree

2 files changed

+20
-8
lines changed

2 files changed

+20
-8
lines changed

Zend/zend_default_classes.c

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -340,9 +340,15 @@ ZEND_METHOD(exception, __toString)
340340

341341
zend_call_function(&fci, NULL TSRMLS_CC);
342342

343-
len = zend_spprintf(&str, 0, "exception '%s' with message '%s' in %s:%ld\nStack trace:\n%s",
344-
Z_OBJCE_P(getThis())->name, Z_STRVAL_P(message), Z_STRVAL_P(file), Z_LVAL_P(line),
345-
Z_STRLEN_P(trace) ? Z_STRVAL_P(trace) : "#0 {main}\n");
343+
if (Z_STRLEN_P(message) > 0) {
344+
len = zend_spprintf(&str, 0, "exception '%s' with message '%s' in %s:%ld\nStack trace:\n%s",
345+
Z_OBJCE_P(getThis())->name, Z_STRVAL_P(message), Z_STRVAL_P(file), Z_LVAL_P(line),
346+
Z_STRLEN_P(trace) ? Z_STRVAL_P(trace) : "#0 {main}\n");
347+
} else {
348+
len = zend_spprintf(&str, 0, "exception '%s' in %s:%ld\nStack trace:\n%s",
349+
Z_OBJCE_P(getThis())->name, Z_STRVAL_P(file), Z_LVAL_P(line),
350+
Z_STRLEN_P(trace) ? Z_STRVAL_P(trace) : "#0 {main}\n");
351+
}
346352

347353
/* We store the result in the private property string so we can access
348354
* the result in uncaught exception handlers without memleaks. */
@@ -385,7 +391,7 @@ static void zend_register_default_exception(TSRMLS_D)
385391
memcpy(&default_exception_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers));
386392
default_exception_handlers.clone_obj = NULL;
387393

388-
zend_declare_property_string(default_exception_ptr, "message", sizeof("message")-1, "none", ZEND_ACC_PROTECTED TSRMLS_CC);
394+
zend_declare_property_string(default_exception_ptr, "message", sizeof("message")-1, "", ZEND_ACC_PROTECTED TSRMLS_CC);
389395
zend_declare_property_string(default_exception_ptr, "string", sizeof("string")-1, "", ZEND_ACC_PRIVATE TSRMLS_CC);
390396
zend_declare_property_long(default_exception_ptr, "code", sizeof("code")-1, 0, ZEND_ACC_PROTECTED TSRMLS_CC);
391397
zend_declare_property_null(default_exception_ptr, "file", sizeof("file")-1, ZEND_ACC_PROTECTED TSRMLS_CC);

Zend/zend_exceptions.c

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -340,9 +340,15 @@ ZEND_METHOD(exception, __toString)
340340

341341
zend_call_function(&fci, NULL TSRMLS_CC);
342342

343-
len = zend_spprintf(&str, 0, "exception '%s' with message '%s' in %s:%ld\nStack trace:\n%s",
344-
Z_OBJCE_P(getThis())->name, Z_STRVAL_P(message), Z_STRVAL_P(file), Z_LVAL_P(line),
345-
Z_STRLEN_P(trace) ? Z_STRVAL_P(trace) : "#0 {main}\n");
343+
if (Z_STRLEN_P(message) > 0) {
344+
len = zend_spprintf(&str, 0, "exception '%s' with message '%s' in %s:%ld\nStack trace:\n%s",
345+
Z_OBJCE_P(getThis())->name, Z_STRVAL_P(message), Z_STRVAL_P(file), Z_LVAL_P(line),
346+
Z_STRLEN_P(trace) ? Z_STRVAL_P(trace) : "#0 {main}\n");
347+
} else {
348+
len = zend_spprintf(&str, 0, "exception '%s' in %s:%ld\nStack trace:\n%s",
349+
Z_OBJCE_P(getThis())->name, Z_STRVAL_P(file), Z_LVAL_P(line),
350+
Z_STRLEN_P(trace) ? Z_STRVAL_P(trace) : "#0 {main}\n");
351+
}
346352

347353
/* We store the result in the private property string so we can access
348354
* the result in uncaught exception handlers without memleaks. */
@@ -385,7 +391,7 @@ static void zend_register_default_exception(TSRMLS_D)
385391
memcpy(&default_exception_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers));
386392
default_exception_handlers.clone_obj = NULL;
387393

388-
zend_declare_property_string(default_exception_ptr, "message", sizeof("message")-1, "none", ZEND_ACC_PROTECTED TSRMLS_CC);
394+
zend_declare_property_string(default_exception_ptr, "message", sizeof("message")-1, "", ZEND_ACC_PROTECTED TSRMLS_CC);
389395
zend_declare_property_string(default_exception_ptr, "string", sizeof("string")-1, "", ZEND_ACC_PRIVATE TSRMLS_CC);
390396
zend_declare_property_long(default_exception_ptr, "code", sizeof("code")-1, 0, ZEND_ACC_PROTECTED TSRMLS_CC);
391397
zend_declare_property_null(default_exception_ptr, "file", sizeof("file")-1, ZEND_ACC_PROTECTED TSRMLS_CC);

0 commit comments

Comments
 (0)