-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Promote warnings to exceptions in ext/xmlreader #6021
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 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -175,7 +175,7 @@ zval *xmlreader_write_property(zend_object *object, zend_string *name, zval *val | |
hnd = zend_hash_find_ptr(obj->prop_handler, name); | ||
} | ||
if (hnd != NULL) { | ||
php_error_docref(NULL, E_WARNING, "Cannot write to read-only property"); | ||
zend_throw_error(NULL, "Cannot write to read-only property"); | ||
} else { | ||
value = zend_std_write_property(object, name, value, cache_slot); | ||
} | ||
|
@@ -391,8 +391,8 @@ static void php_xmlreader_string_arg(INTERNAL_FUNCTION_PARAMETERS, xmlreader_rea | |
} | ||
|
||
if (!name_len) { | ||
php_error_docref(NULL, E_WARNING, "Argument cannot be an empty string"); | ||
RETURN_FALSE; | ||
zend_argument_value_error(1, "cannot be empty"); | ||
RETURN_THROWS(); | ||
} | ||
|
||
id = ZEND_THIS; | ||
|
@@ -480,8 +480,8 @@ static void php_xmlreader_set_relaxng_schema(INTERNAL_FUNCTION_PARAMETERS, int t | |
} | ||
|
||
if (source != NULL && !source_len) { | ||
php_error_docref(NULL, E_WARNING, "Schema data source is required"); | ||
RETURN_FALSE; | ||
zend_argument_value_error(1, "cannot be empty"); | ||
RETURN_THROWS(); | ||
} | ||
|
||
id = ZEND_THIS; | ||
|
@@ -509,9 +509,8 @@ static void php_xmlreader_set_relaxng_schema(INTERNAL_FUNCTION_PARAMETERS, int t | |
} | ||
} | ||
|
||
php_error_docref(NULL, E_WARNING, "Unable to set schema. This must be set prior to reading or schema contains errors."); | ||
|
||
RETURN_FALSE; | ||
zend_throw_error(NULL, "Unable to set schema. This must be set prior to reading or schema contains errors."); | ||
RETURN_THROWS(); | ||
#else | ||
php_error_docref(NULL, E_WARNING, "No Schema support built into libxml."); | ||
|
||
|
@@ -585,9 +584,14 @@ PHP_METHOD(XMLReader, getAttributeNs) | |
RETURN_THROWS(); | ||
} | ||
|
||
if (name_len == 0 || ns_uri_len == 0) { | ||
php_error_docref(NULL, E_WARNING, "Attribute Name and Namespace URI cannot be empty"); | ||
RETURN_FALSE; | ||
if (name_len == 0) { | ||
zend_argument_value_error(1, "cannot be empty"); | ||
RETURN_THROWS(); | ||
} | ||
|
||
if (ns_uri_len == 0) { | ||
zend_argument_value_error(2, "cannot be empty"); | ||
RETURN_THROWS(); | ||
} | ||
|
||
id = ZEND_THIS; | ||
|
@@ -622,8 +626,8 @@ PHP_METHOD(XMLReader, getParserProperty) | |
retval = xmlTextReaderGetParserProp(intern->ptr,property); | ||
} | ||
if (retval == -1) { | ||
php_error_docref(NULL, E_WARNING, "Invalid parser property"); | ||
RETURN_FALSE; | ||
zend_argument_value_error(1, "must be a valid parser property"); | ||
RETURN_THROWS(); | ||
} | ||
|
||
RETURN_BOOL(retval); | ||
|
@@ -660,8 +664,8 @@ PHP_METHOD(XMLReader, moveToAttribute) | |
} | ||
|
||
if (name_len == 0) { | ||
php_error_docref(NULL, E_WARNING, "Attribute Name is required"); | ||
RETURN_FALSE; | ||
zend_argument_value_error(1, "cannot be empty"); | ||
RETURN_THROWS(); | ||
} | ||
|
||
id = ZEND_THIS; | ||
|
@@ -719,9 +723,14 @@ PHP_METHOD(XMLReader, moveToAttributeNs) | |
RETURN_THROWS(); | ||
} | ||
|
||
if (name_len == 0 || ns_uri_len == 0) { | ||
php_error_docref(NULL, E_WARNING, "Attribute Name and Namespace URI cannot be empty"); | ||
RETURN_FALSE; | ||
if (name_len == 0) { | ||
zend_argument_value_error(1, "cannot be empty"); | ||
RETURN_THROWS(); | ||
} | ||
|
||
if (ns_uri_len == 0) { | ||
zend_argument_value_error(2, "cannot be empty"); | ||
RETURN_THROWS(); | ||
} | ||
|
||
id = ZEND_THIS; | ||
|
@@ -781,8 +790,7 @@ PHP_METHOD(XMLReader, read) | |
} | ||
} | ||
|
||
php_error_docref(NULL, E_WARNING, "Load Data before trying to read"); | ||
RETURN_FALSE; | ||
zend_throw_error(NULL, "Data must be loaded before reading"); | ||
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. Style nit: Rewrite this as early return? 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. Makes sense for me! |
||
} | ||
/* }}} */ | ||
|
||
|
@@ -816,8 +824,7 @@ PHP_METHOD(XMLReader, next) | |
} | ||
} | ||
|
||
php_error_docref(NULL, E_WARNING, "Load Data before trying to read"); | ||
RETURN_FALSE; | ||
zend_throw_error(NULL, "Data must be loaded before reading"); | ||
} | ||
/* }}} */ | ||
|
||
|
@@ -848,8 +855,8 @@ PHP_METHOD(XMLReader, open) | |
} | ||
|
||
if (!source_len) { | ||
php_error_docref(NULL, E_WARNING, "Empty string supplied as input"); | ||
RETURN_FALSE; | ||
zend_argument_value_error(1, "cannot be empty"); | ||
RETURN_THROWS(); | ||
} | ||
|
||
valid_file = _xmlreader_get_valid_file_path(source, resolved_path, MAXPATHLEN ); | ||
|
@@ -920,8 +927,8 @@ PHP_METHOD(XMLReader, setSchema) | |
} | ||
|
||
if (source != NULL && !source_len) { | ||
php_error_docref(NULL, E_WARNING, "Schema data source is required"); | ||
RETURN_FALSE; | ||
zend_argument_value_error(1, "cannot be empty"); | ||
RETURN_THROWS(); | ||
} | ||
|
||
id = ZEND_THIS; | ||
|
@@ -935,9 +942,8 @@ PHP_METHOD(XMLReader, setSchema) | |
} | ||
} | ||
|
||
php_error_docref(NULL, E_WARNING, "Unable to set schema. This must be set prior to reading or schema contains errors."); | ||
|
||
RETURN_FALSE; | ||
zend_throw_error(NULL, "Unable to set schema. This must be set prior to reading or schema contains errors."); | ||
RETURN_THROWS(); | ||
#else | ||
php_error_docref(NULL, E_WARNING, "No Schema support built into libxml."); | ||
|
||
|
@@ -967,8 +973,8 @@ PHP_METHOD(XMLReader, setParserProperty) | |
retval = xmlTextReaderSetParserProp(intern->ptr,property, value); | ||
} | ||
if (retval == -1) { | ||
php_error_docref(NULL, E_WARNING, "Invalid parser property"); | ||
RETURN_FALSE; | ||
zend_argument_value_error(1, "must be a valid parser property"); | ||
RETURN_THROWS(); | ||
} | ||
|
||
RETURN_TRUE; | ||
|
@@ -1022,8 +1028,8 @@ PHP_METHOD(XMLReader, XML) | |
} | ||
|
||
if (!source_len) { | ||
php_error_docref(NULL, E_WARNING, "Empty string supplied as input"); | ||
RETURN_FALSE; | ||
zend_argument_value_error(1, "cannot be empty"); | ||
RETURN_THROWS(); | ||
} | ||
|
||
inputbfr = xmlParserInputBufferCreateMem(source, source_len, XML_CHAR_ENCODING_NONE); | ||
|
@@ -1105,7 +1111,7 @@ PHP_METHOD(XMLReader, expand) | |
node = xmlTextReaderExpand(intern->ptr); | ||
|
||
if (node == NULL) { | ||
php_error_docref(NULL, E_WARNING, "An Error Occurred while expanding "); | ||
php_error_docref(NULL, E_WARNING, "An Error Occurred while expanding"); | ||
RETURN_FALSE; | ||
} else { | ||
nodec = xmlDocCopyNode(node, docp, 1); | ||
|
@@ -1117,8 +1123,8 @@ PHP_METHOD(XMLReader, expand) | |
} | ||
} | ||
} else { | ||
php_error_docref(NULL, E_WARNING, "Load Data before trying to expand"); | ||
RETURN_FALSE; | ||
zend_throw_error(NULL, "Data must be loaded before expanding"); | ||
RETURN_THROWS(); | ||
} | ||
#else | ||
php_error(E_WARNING, "DOM support is not enabled"); | ||
|
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
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
Oops, something went wrong.
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.
"schema contains errors" doesn't sound like a promotable condition.
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.
I think this needs to be split into the error condition for
!intern || !intern->ptr
(can throw) and the one for retval != 0 (cannot throw).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 recommendation, I managed to separate them, and I added test coverage for both the warning and the exception.