-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Promote warnings to exceptions in ext/simplexml #6011
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
3b1680a
Promote warnings to exceptions in ext/simplexml
kocsismate 6037ea7
Address code review
kocsismate 0f7c6c6
Remove useless test
kocsismate 644dba8
Fix spelling and omitted return
kocsismate 70b7ca6
Correctly report exception in SXE get_property_ptr_ptr
nikic File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -411,7 +411,7 @@ static zval *sxe_prop_dim_write(zend_object *object, zval *member, zval *value, | |
* and could also be E_PARSE, but we use this only during parsing | ||
* and this is during runtime. | ||
*/ | ||
zend_throw_error(NULL, "Cannot create unnamed attribute"); | ||
zend_throw_error(NULL, "Cannot append to an attribute list"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd leave only the first line of the preceding comment. |
||
return &EG(error_zval); | ||
} | ||
goto long_dim; | ||
|
@@ -436,7 +436,7 @@ static zval *sxe_prop_dim_write(zend_object *object, zval *member, zval *value, | |
} | ||
|
||
if (!Z_STRLEN_P(member)) { | ||
php_error_docref(NULL, E_WARNING, "Cannot write or create unnamed %s", attribs ? "attribute" : "element"); | ||
zend_value_error("Cannot create %s with an empty name", attribs ? "attribute" : "element"); | ||
if (member == &tmp_zv) { | ||
zval_ptr_dtor_str(&tmp_zv); | ||
} | ||
|
@@ -464,7 +464,7 @@ static zval *sxe_prop_dim_write(zend_object *object, zval *member, zval *value, | |
* and could also be E_PARSE, but we use this only during parsing | ||
* and this is during runtime. | ||
*/ | ||
zend_throw_error(NULL, "Cannot create unnamed attribute"); | ||
zend_value_error("Cannot append to an attribute list"); | ||
return &EG(error_zval); | ||
} | ||
if (attribs && !node && sxe->iter.type == SXE_ITER_ELEMENT) { | ||
|
@@ -489,8 +489,8 @@ static zval *sxe_prop_dim_write(zend_object *object, zval *member, zval *value, | |
if (Z_OBJCE_P(value) == sxe_class_entry) { | ||
zval zval_copy; | ||
if (sxe_object_cast_ex(Z_OBJ_P(value), &zval_copy, IS_STRING) == FAILURE) { | ||
zend_error(E_ERROR, "Unable to cast node to string"); | ||
kocsismate marked this conversation as resolved.
Show resolved
Hide resolved
|
||
/* FIXME: Should not be fatal */ | ||
zend_throw_error(NULL, "Unable to cast node to string"); | ||
return &EG(error_zval); | ||
} | ||
|
||
value_str = Z_STR(zval_copy); | ||
|
@@ -501,7 +501,7 @@ static zval *sxe_prop_dim_write(zend_object *object, zval *member, zval *value, | |
if (member == &tmp_zv) { | ||
zval_ptr_dtor_str(&tmp_zv); | ||
} | ||
zend_error(E_WARNING, "It is not yet possible to assign complex types to %s", attribs ? "attributes" : "properties"); | ||
zend_type_error("It's not possible to assign a complex type to %s, %s given", attribs ? "attributes" : "properties", zend_zval_type_name(value)); | ||
return &EG(error_zval); | ||
} | ||
} | ||
|
@@ -656,7 +656,7 @@ static zval *sxe_property_get_adr(zend_object *object, zend_string *zname, int f | |
} | ||
ZVAL_STR(&member, zname); | ||
if (sxe_prop_dim_write(object, &member, NULL, 1, 0, &node) == &EG(error_zval)) { | ||
return NULL; | ||
return &EG(error_zval); | ||
} | ||
type = SXE_ITER_NONE; | ||
name = NULL; | ||
|
@@ -1684,8 +1684,8 @@ SXE_METHOD(addChild) | |
} | ||
|
||
if (qname_len == 0) { | ||
php_error_docref(NULL, E_WARNING, "Element name is required"); | ||
return; | ||
zend_argument_value_error(1, "cannot be empty"); | ||
RETURN_THROWS(); | ||
} | ||
|
||
sxe = Z_SXEOBJ_P(ZEND_THIS); | ||
|
@@ -1749,8 +1749,8 @@ SXE_METHOD(addAttribute) | |
} | ||
|
||
if (qname_len == 0) { | ||
php_error_docref(NULL, E_WARNING, "Attribute name is required"); | ||
return; | ||
zend_argument_value_error(1, "cannot be empty"); | ||
RETURN_THROWS(); | ||
} | ||
|
||
sxe = Z_SXEOBJ_P(ZEND_THIS); | ||
|
@@ -2274,8 +2274,8 @@ PHP_FUNCTION(simplexml_load_file) | |
} | ||
|
||
if (ZEND_LONG_EXCEEDS_INT(options)) { | ||
php_error_docref(NULL, E_WARNING, "Invalid options"); | ||
RETURN_FALSE; | ||
zend_argument_value_error(3, "is too large"); | ||
RETURN_THROWS(); | ||
} | ||
|
||
docp = xmlReadFile(filename, NULL, (int)options); | ||
|
@@ -2319,16 +2319,16 @@ PHP_FUNCTION(simplexml_load_string) | |
} | ||
|
||
if (ZEND_SIZE_T_INT_OVFL(data_len)) { | ||
php_error_docref(NULL, E_WARNING, "Data is too long"); | ||
RETURN_FALSE; | ||
zend_argument_value_error(1, "is too long"); | ||
RETURN_THROWS(); | ||
} | ||
if (ZEND_SIZE_T_INT_OVFL(ns_len)) { | ||
php_error_docref(NULL, E_WARNING, "Namespace is too long"); | ||
RETURN_FALSE; | ||
zend_argument_value_error(4, "is too long"); | ||
RETURN_THROWS(); | ||
} | ||
if (ZEND_LONG_EXCEEDS_INT(options)) { | ||
php_error_docref(NULL, E_WARNING, "Invalid options"); | ||
RETURN_FALSE; | ||
zend_argument_value_error(3, "is too large"); | ||
RETURN_THROWS(); | ||
} | ||
|
||
docp = xmlReadMemory(data, (int)data_len, NULL, NULL, (int)options); | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,10 +8,16 @@ Havard Eide <[email protected]> | |
--FILE-- | ||
<?php | ||
$a = new SimpleXMLElement("<php>testfest</php>"); | ||
$a->addAttribute( "", "" ); | ||
|
||
try { | ||
$a->addAttribute( "", "" ); | ||
} catch (ValueError $exception) { | ||
echo $exception->getMessage() . "\n"; | ||
} | ||
|
||
echo $a->asXML(); | ||
?> | ||
--EXPECTF-- | ||
Warning: SimpleXMLElement::addAttribute(): Attribute name is required in %s on line %d | ||
--EXPECT-- | ||
SimpleXMLElement::addAttribute(): Argument #1 ($qualifiedName) cannot be empty | ||
<?xml version="1.0"?> | ||
<php>testfest</php> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the this explanation, it's really useful! Of course, I'm grateful for the fix, too :)