-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Promote warnings to exceptions in ext/intl #5972
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
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -114,8 +114,8 @@ PHP_FUNCTION(grapheme_strpos) | |
} | ||
|
||
if ( OUTSIDE_STRING(loffset, haystack_len) ) { | ||
intl_error_set( NULL, U_ILLEGAL_ARGUMENT_ERROR, "grapheme_strpos: Offset not contained in string", 1 ); | ||
RETURN_FALSE; | ||
zend_argument_value_error(3, "must be contained in argument #1 ($haystack)"); | ||
RETURN_THROWS(); | ||
} | ||
|
||
/* we checked that it will fit: */ | ||
|
@@ -125,8 +125,8 @@ PHP_FUNCTION(grapheme_strpos) | |
/* the offset is 'grapheme count offset' so it still might be invalid - we'll check it later */ | ||
|
||
if (needle_len == 0) { | ||
intl_error_set( NULL, U_ILLEGAL_ARGUMENT_ERROR, "grapheme_strpos: Empty delimiter", 1 ); | ||
RETURN_FALSE; | ||
zend_argument_value_error(2, "cannot be empty"); | ||
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. Hmm, there is no such warning in 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. Yes, we should add support for empty string here. |
||
RETURN_THROWS(); | ||
} | ||
|
||
if (offset >= 0) { | ||
|
@@ -154,7 +154,6 @@ PHP_FUNCTION(grapheme_strpos) | |
} else { | ||
RETURN_FALSE; | ||
} | ||
|
||
} | ||
/* }}} */ | ||
|
||
|
@@ -174,8 +173,8 @@ PHP_FUNCTION(grapheme_stripos) | |
} | ||
|
||
if ( OUTSIDE_STRING(loffset, haystack_len) ) { | ||
intl_error_set( NULL, U_ILLEGAL_ARGUMENT_ERROR, "grapheme_stripos: Offset not contained in string", 1 ); | ||
RETURN_FALSE; | ||
zend_argument_value_error(3, "must be contained in argument #1 ($haystack)"); | ||
RETURN_THROWS(); | ||
} | ||
|
||
/* we checked that it will fit: */ | ||
|
@@ -184,8 +183,8 @@ PHP_FUNCTION(grapheme_stripos) | |
/* the offset is 'grapheme count offset' so it still might be invalid - we'll check it later */ | ||
|
||
if (needle_len == 0) { | ||
intl_error_set( NULL, U_ILLEGAL_ARGUMENT_ERROR, "grapheme_stripos: Empty delimiter", 1 ); | ||
RETURN_FALSE; | ||
zend_argument_value_error(2, "cannot be empty"); | ||
RETURN_THROWS(); | ||
} | ||
|
||
is_ascii = ( grapheme_ascii_check((unsigned char*)haystack, haystack_len) >= 0 ); | ||
|
@@ -240,8 +239,8 @@ PHP_FUNCTION(grapheme_strrpos) | |
} | ||
|
||
if ( OUTSIDE_STRING(loffset, haystack_len) ) { | ||
intl_error_set( NULL, U_ILLEGAL_ARGUMENT_ERROR, "grapheme_strpos: Offset not contained in string", 1 ); | ||
RETURN_FALSE; | ||
zend_argument_value_error(3, "must be contained in argument #1 ($haystack)"); | ||
RETURN_THROWS(); | ||
} | ||
|
||
/* we checked that it will fit: */ | ||
|
@@ -250,8 +249,8 @@ PHP_FUNCTION(grapheme_strrpos) | |
/* the offset is 'grapheme count offset' so it still might be invalid - we'll check it later */ | ||
|
||
if (needle_len == 0) { | ||
intl_error_set( NULL, U_ILLEGAL_ARGUMENT_ERROR, "grapheme_strpos: Empty delimiter", 1 ); | ||
RETURN_FALSE; | ||
zend_argument_value_error(2, "cannot be empty"); | ||
RETURN_THROWS(); | ||
} | ||
|
||
is_ascii = grapheme_ascii_check((unsigned char *)haystack, haystack_len) >= 0; | ||
|
@@ -300,8 +299,8 @@ PHP_FUNCTION(grapheme_strripos) | |
} | ||
|
||
if ( OUTSIDE_STRING(loffset, haystack_len) ) { | ||
intl_error_set( NULL, U_ILLEGAL_ARGUMENT_ERROR, "grapheme_strpos: Offset not contained in string", 1 ); | ||
RETURN_FALSE; | ||
zend_argument_value_error(3, "must be contained in argument #1 ($haystack)"); | ||
RETURN_THROWS(); | ||
} | ||
|
||
/* we checked that it will fit: */ | ||
|
@@ -310,8 +309,8 @@ PHP_FUNCTION(grapheme_strripos) | |
/* the offset is 'grapheme count offset' so it still might be invalid - we'll check it later */ | ||
|
||
if (needle_len == 0) { | ||
intl_error_set( NULL, U_ILLEGAL_ARGUMENT_ERROR, "grapheme_strpos: Empty delimiter", 1 ); | ||
RETURN_FALSE; | ||
zend_argument_value_error(2, "cannot be empty"); | ||
RETURN_THROWS(); | ||
} | ||
|
||
is_ascii = grapheme_ascii_check((unsigned char *)haystack, haystack_len) >= 0; | ||
|
@@ -377,8 +376,8 @@ PHP_FUNCTION(grapheme_substr) | |
} | ||
|
||
if ( OUTSIDE_STRING(lstart, str_len)) { | ||
intl_error_set( NULL, U_ILLEGAL_ARGUMENT_ERROR, "grapheme_substr: start not contained in string", 1 ); | ||
RETURN_FALSE; | ||
zend_argument_value_error(2, "must be contained in argument #1 ($string)"); | ||
RETURN_THROWS(); | ||
} | ||
|
||
/* we checked that it will fit: */ | ||
|
@@ -532,10 +531,9 @@ PHP_FUNCTION(grapheme_substr) | |
|
||
if ( UBRK_DONE == sub_str_end_pos) { | ||
if(length < 0) { | ||
intl_error_set( NULL, U_ILLEGAL_ARGUMENT_ERROR, "grapheme_substr: length not contained in string", 1 ); | ||
|
||
zend_argument_value_error(3, "must be contained in argument #1 ($string)"); | ||
efree(ustr); | ||
RETURN_FALSE; | ||
RETURN_THROWS(); | ||
} else { | ||
sub_str_end_pos = ustr_len; | ||
} | ||
|
@@ -582,13 +580,10 @@ static void strstr_common_handler(INTERNAL_FUNCTION_PARAMETERS, int f_ignore_cas | |
} | ||
|
||
if (needle_len == 0) { | ||
|
||
intl_error_set( NULL, U_ILLEGAL_ARGUMENT_ERROR, "grapheme_strpos: Empty delimiter", 1 ); | ||
|
||
RETURN_FALSE; | ||
zend_argument_value_error(2, "cannot be empty"); | ||
RETURN_THROWS(); | ||
} | ||
|
||
|
||
if ( !f_ignore_case ) { | ||
|
||
/* ASCII optimization: quick check to see if the string might be there | ||
|
@@ -783,20 +778,25 @@ PHP_FUNCTION(grapheme_extract) | |
} | ||
|
||
if ( extract_type < GRAPHEME_EXTRACT_TYPE_MIN || extract_type > GRAPHEME_EXTRACT_TYPE_MAX ) { | ||
intl_error_set( NULL, U_ILLEGAL_ARGUMENT_ERROR, | ||
"grapheme_extract: unknown extract type param", 0 ); | ||
RETURN_FALSE; | ||
zend_argument_value_error(3, "must be either GRAPHEME_EXTR_COUNT, GRAPHEME_EXTR_MAXBYTES, or GRAPHEME_EXTR_MAXCHARS"); | ||
RETURN_THROWS(); | ||
} | ||
|
||
if ( lstart > INT32_MAX || lstart < 0 || (size_t)lstart >= str_len ) { | ||
intl_error_set( NULL, U_ILLEGAL_ARGUMENT_ERROR, "grapheme_extract: start not contained in string", 0 ); | ||
RETURN_FALSE; | ||
} | ||
|
||
if ( size > INT32_MAX || size < 0) { | ||
intl_error_set( NULL, U_ILLEGAL_ARGUMENT_ERROR, "grapheme_extract: size is invalid", 0 ); | ||
RETURN_FALSE; | ||
if (size < 0) { | ||
zend_argument_value_error(2, "must be greater than or equal to 0"); | ||
RETURN_THROWS(); | ||
} | ||
|
||
if ( size > INT32_MAX) { | ||
kocsismate marked this conversation as resolved.
Show resolved
Hide resolved
|
||
zend_argument_value_error(2, "is too large"); | ||
RETURN_THROWS(); | ||
} | ||
|
||
if (size == 0) { | ||
RETURN_EMPTY_STRING(); | ||
} | ||
|
Uh oh!
There was an error while loading. Please reload this page.