Skip to content

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

Closed
wants to merge 5 commits into from

Conversation

kocsismate
Copy link
Member

@kocsismate kocsismate commented Aug 10, 2020

There is quite a few intl_error_set() invocations remaining, out of which probably a few could also be promoted to an exception.

@@ -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");
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, there is no such warning in strpos(), so maybe we could get rid of this error? On the other hand, the offset is not contained... case has been promoted to an exception in strpos(), so I'll do it here as well.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, we should add support for empty string here.

@@ -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");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, we should add support for empty string here.

Copy link
Member

@nikic nikic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Marking as reviewed.

int(3)
int(3)
string(3) "abc"
bool(false)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this one also be string(3) "abc"?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, yes.. I thought that the removed check from strstr_common_handler() was inside if ( !f_ignore_case ) {}, thus it only applies to grapheme_strstr. And when I double-checked it on 3v4n, the intl.error_level tricked me, since there is no error shown by default.

That said, I'll try to fix this.

Copy link
Member Author

@kocsismate kocsismate Sep 2, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reason of the false return value is this check in grapheme_strpos_utf16():

src = usearch_open(uneedle, uneedle_len, uhaystack, uhaystack_len, "", bi, &status);
STRPOS_CHECK_STATUS(status, "Error creating search object");

To make things worse, grapheme_strpos_utf16() is called in the other grapheme string functions when the offset is below 0, so e.g. grapheme_strpos("abc", "", -1) also fails currently.

I don't see any easy solution for the problem because usearch_open() is third-party code, otherwise we could just add a similar check for empty needle what George added to zend_memnstr(). @nikic Do you know about any good solution that circumvents this problem? Is it a very big problem if grapheme_() functions can't handle empty needles?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like the relevant icu code is: https://github.com/unicode-org/icu/blob/f744742e036441cbfd54b535e722dc3801ff0f63/icu4c/source/i18n/usearch.cpp#L2675

I think we should add an explicit check for this case then. I do think it would be good to support empty strings here, as we also added support for them in ext/standard and ext/mbstring (I'm not sure about ext/iconv right now).

Copy link
Member Author

@kocsismate kocsismate Sep 7, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've reverted the change in question, but added a task

@nikic
Copy link
Member

nikic commented Sep 7, 2020

Travis still failing.

@kocsismate
Copy link
Member Author

@nikic Yeah, I'll fix it too. It didn't run on my machine due to incompatible icu version.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants