-
Couldn't load subscription status.
- Fork 8k
ext/intl: SpoofChecker::setAllowedChars support. #14433
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
Conversation
7f8885f to
4c4605f
Compare
9d25674 to
b50fc05
Compare
| /** @tentative-return-type */ | ||
| public function setRestrictionLevel(int $level): void {} | ||
| #endif | ||
| public function setAllowedChars(string $pattern, int $pattern_options = 0): void {} |
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.
The parameter naming style should follow the extension's naming style, which is camelCase.
| public function setAllowedChars(string $pattern, int $pattern_options = 0): void {} | |
| public function setAllowedChars(string $pattern, int $patternOptions = 0): void {} |
| SPOOFCHECKER_METHOD_FETCH_OBJECT; | ||
|
|
||
| if (ZSTR_LEN(pattern) > INT32_MAX) { | ||
| zend_argument_value_error(1, "is larger than " ZEND_LONG_FMT, INT32_MAX); |
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.
This is the most common wording:
| zend_argument_value_error(1, "is larger than " ZEND_LONG_FMT, INT32_MAX); | |
| zend_argument_value_error(1, "must be less than or equal to " ZEND_LONG_FMT " bytes", INT32_MAX); |
|
|
||
| /* uset_applyPattern requires to start with a regex range char */ | ||
| if (ZSTR_VAL(pattern)[0] != '[') { | ||
| zend_argument_value_error(1, "invalid pattern"); |
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.
The sentence becomes correct this way:
| zend_argument_value_error(1, "invalid pattern"); | |
| zend_argument_value_error(1, "is an invalid pattern"); |
|
|
||
| intl_convert_utf8_to_utf16(&upattern, &upattern_len, ZSTR_VAL(pattern), ZSTR_LEN(pattern), SPOOFCHECKER_ERROR_CODE_P(co)); | ||
| if (U_FAILURE(SPOOFCHECKER_ERROR_CODE(co))) { | ||
| zend_argument_value_error(1, "string conversion to utf-16 failed (%d) %s", SPOOFCHECKER_ERROR_CODE(co), u_errorName(SPOOFCHECKER_ERROR_CODE(co))); |
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.
this error message should also be improved
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.
the same goes for the rest as well
b50fc05 to
c2815dc
Compare
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.
Looks almost good
| efree(upattern); | ||
|
|
||
| if (U_FAILURE(SPOOFCHECKER_ERROR_CODE(co))) { | ||
| php_error_docref(NULL, E_WARNING, "(%d) %s", SPOOFCHECKER_ERROR_CODE(co), u_errorName(SPOOFCHECKER_ERROR_CODE(co))); |
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.
A bit unfortunate of an API design, but at least consistent with what we have, so 🤷
c2815dc to
7b8ce1c
Compare
|
|
||
| /* uset_applyPattern requires to start with a regex range char */ | ||
| if (ZSTR_VAL(pattern)[0] != '[' || ZSTR_VAL(pattern)[ZSTR_LEN(pattern) -1] != ']') { | ||
| zend_argument_value_error(1, "must be an invalid pattern"); |
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.
| zend_argument_value_error(1, "must be an invalid pattern"); | |
| zend_argument_value_error(1, "must be a valid pattern"); |
Or perhaps we should even hint in the error message that this should be a regex character range.
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 also think that the "is a" vs "must be" error messages should be done consistently in this function.
7b8ce1c to
9f840a9
Compare
|
|
||
| uset_applyPattern(set, upattern, upattern_len, (uint32_t)pattern_option, SPOOFCHECKER_ERROR_CODE_P(co)); | ||
| if (U_FAILURE(SPOOFCHECKER_ERROR_CODE(co))) { | ||
| zend_argument_value_error(1, "must be a invalid pattern (%d) %s", SPOOFCHECKER_ERROR_CODE(co), u_errorName(SPOOFCHECKER_ERROR_CODE(co))); |
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.
| zend_argument_value_error(1, "must be a invalid pattern (%d) %s", SPOOFCHECKER_ERROR_CODE(co), u_errorName(SPOOFCHECKER_ERROR_CODE(co))); | |
| zend_argument_value_error(1, "must be a valid regular expression character set pattern (%d) %s", SPOOFCHECKER_ERROR_CODE(co), u_errorName(SPOOFCHECKER_ERROR_CODE(co))); |
ext/intl/tests/spoofchecker_008.phpt
Outdated
| bool(true) | ||
| bool(false) | ||
| bool(false) | ||
| Spoofchecker::setAllowedChars(): Argument #2 ($patternOptions) must be a valid pattern option, 0 or (SpoofChecker::IGNORE_SPACE|(<none> or SpoofChecker::USET_CASE_INSENSITIVE or SpoofChecker::USET_ADD_CASE_MAPPINGS or SpoofChecker::USET_SIMPLE_CASE_INSENSITIVE)) |
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.
You lost the %s thingie here
|
|
||
| /* uset_applyPattern requires to start with a regex range char */ | ||
| if (ZSTR_VAL(pattern)[0] != '[' || ZSTR_VAL(pattern)[ZSTR_LEN(pattern) -1] != ']') { | ||
| zend_argument_value_error(1, "must be a valid pattern"); |
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.
| zend_argument_value_error(1, "must be a valid pattern"); | |
| zend_argument_value_error(1, "must be a valid regular expression character set pattern"); |
To limit the acceptable range of acceptable unicode chars via individual ones or via a pattern.
9f840a9 to
b29b569
Compare
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.
LGTM if CI is green.
I pulled this locally and played a bit with it, and I think it seems good.
Sorry it took so long for the final review, I thought someone else was gonna review it and then forgot that I initially commented on this.
|
Thanks for your review |
|
Merge with 21418b5 |
To limit the acceptable range of acceptable unicode chars via individual ones or via a pattern.