Skip to content

intl: use uspoof_check2UTF8 call when available. #9478

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

Merged
merged 1 commit into from
Sep 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions ext/intl/spoofchecker/spoofchecker_class.c
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,13 @@ void spoofchecker_object_destroy(Spoofchecker_object* co)
co->uspoof = NULL;
}

#if U_ICU_VERSION_MAJOR_NUM >= 58
if (co->uspoofres) {
uspoof_closeCheckResult(co->uspoofres);
co->uspoofres = NULL;
}
#endif

intl_error_reset(SPOOFCHECKER_ERROR_P(co));
}
/* }}} */
5 changes: 4 additions & 1 deletion ext/intl/spoofchecker/spoofchecker_class.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,10 @@ typedef struct {
intl_error err;

// ICU Spoofchecker
USpoofChecker* uspoof;
USpoofChecker* uspoof;
#if U_ICU_VERSION_MAJOR_NUM >= 58
USpoofCheckResult* uspoofres;
#endif

zend_object zo;
} Spoofchecker_object;
Expand Down
1 change: 1 addition & 0 deletions ext/intl/spoofchecker/spoofchecker_create.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ PHP_METHOD(Spoofchecker, __construct)
uspoof_check2 APIs when it became stable, to use extended check result APIs.
Subsequent changes in the unicode security algos are to be watched.*/
uspoof_setRestrictionLevel(co->uspoof, SPOOFCHECKER_DEFAULT_RESTRICTION_LEVEL);
co->uspoofres = uspoof_openCheckResult(SPOOFCHECKER_ERROR_CODE_P(co));
#else
/* Single-script enforcement is on by default. This fails for languages
like Japanese that legally use multiple scripts within a single word,
Expand Down
13 changes: 12 additions & 1 deletion ext/intl/spoofchecker/spoofchecker_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
/* {{{ Checks if a given text contains any suspicious characters */
PHP_METHOD(Spoofchecker, isSuspicious)
{
int ret;
int32_t ret, errmask;
char *text;
size_t text_len;
zval *error_code = NULL;
Expand All @@ -34,10 +34,21 @@ PHP_METHOD(Spoofchecker, isSuspicious)

SPOOFCHECKER_METHOD_FETCH_OBJECT;

#if U_ICU_VERSION_MAJOR_NUM >= 58
ret = uspoof_check2UTF8(co->uspoof, text, text_len, co->uspoofres, SPOOFCHECKER_ERROR_CODE_P(co));
#else
ret = uspoof_checkUTF8(co->uspoof, text, text_len, NULL, SPOOFCHECKER_ERROR_CODE_P(co));
#endif

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)));
#if U_ICU_VERSION_MAJOR_NUM >= 58
errmask = uspoof_getCheckResultChecks(co->uspoofres, SPOOFCHECKER_ERROR_CODE_P(co));

if (errmask != ret) {
php_error_docref(NULL, E_WARNING, "unexpected error (%d), does not relate to the flags passed to setChecks (%d)", ret, errmask);
}
#endif
RETURN_TRUE;
}

Expand Down