Skip to content

Conversation

@devnexen
Copy link
Member

@devnexen devnexen commented Jun 2, 2024

To limit the acceptable range of acceptable unicode chars via individual ones or via a pattern.

@devnexen devnexen force-pushed the spoofchecker_update branch 2 times, most recently from 7f8885f to 4c4605f Compare June 2, 2024 13:14
@TimWolla TimWolla changed the title ext/intl: SpooChecker::setAllowedChars support. ext/intl: SpoofChecker::setAllowedChars support. Jun 2, 2024
@devnexen devnexen force-pushed the spoofchecker_update branch 5 times, most recently from 9d25674 to b50fc05 Compare June 2, 2024 17:57
@devnexen devnexen marked this pull request as ready for review June 2, 2024 19:57
@devnexen devnexen requested a review from kocsismate as a code owner June 2, 2024 19:57
/** @tentative-return-type */
public function setRestrictionLevel(int $level): void {}
#endif
public function setAllowedChars(string $pattern, int $pattern_options = 0): void {}
Copy link
Member

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.

Suggested change
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);
Copy link
Member

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:

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

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:

Suggested change
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)));
Copy link
Member

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

Copy link
Member

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

@devnexen devnexen force-pushed the spoofchecker_update branch from b50fc05 to c2815dc Compare June 21, 2024 22:08
Copy link
Member

@nielsdos nielsdos left a 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)));
Copy link
Member

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 🤷

@devnexen devnexen force-pushed the spoofchecker_update branch from c2815dc to 7b8ce1c Compare July 22, 2024 17:16

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

Choose a reason for hiding this comment

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

Suggested change
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.

Copy link
Member

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.

@devnexen devnexen force-pushed the spoofchecker_update branch from 7b8ce1c to 9f840a9 Compare July 22, 2024 18:06

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

Choose a reason for hiding this comment

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

Suggested change
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)));

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

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

Choose a reason for hiding this comment

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

Suggested change
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.
@devnexen devnexen force-pushed the spoofchecker_update branch from 9f840a9 to b29b569 Compare July 22, 2024 18:22
Copy link
Member

@nielsdos nielsdos left a 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.

@devnexen
Copy link
Member Author

Thanks for your review

@devnexen
Copy link
Member Author

Merge with 21418b5

@devnexen devnexen closed this Jul 22, 2024
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.

3 participants