-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Fix GH-11952: better locale strings canonicalization for IntlDateFormatter and NumberFormatter #19593
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
base: PHP-8.3
Are you sure you want to change the base?
Conversation
6caa975
to
8564487
Compare
UErrorCode status = U_ZERO_ERROR; | ||
int32_t canonicalized_len; | ||
|
||
if (!locale || strlen(locale) == 0) { |
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.
For a (very) quick glance, is there a situation when it can actually happens ?
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're right it seems fine, in the worst case scenario, uloc_getDefault()
is called. I removed this defensive part.
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.
Nice. I ll have a better look sometime tonight. Cheers !
…ormatter and NumberFormatter
8564487
to
7a493fd
Compare
@@ -110,7 +125,16 @@ static zend_result datefmt_ctor(INTERNAL_FUNCTION_PARAMETERS, zend_error_handlin | |||
if (locale_len == 0) { | |||
locale_str = (char *) intl_locale_get_default(); | |||
} | |||
locale = Locale::createFromName(locale_str); | |||
|
|||
char* canonicalized_locale = NULL; |
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.
nit: we re dealing with C99 (C11 I heard ?), you can simplify like this
char *canonicalized_locale = canonicalize_locale_string(locale_str);
const char *final_locale = canonicalized_locale ? canonicalized_locale : locale_str;
const char *stored_locale = canonicalized_locale ? canonicalized_locale : locale_str;
@@ -36,6 +37,20 @@ extern "C" { | |||
#include "dateformat_helpers.h" | |||
#include "zend_exceptions.h" | |||
|
|||
static char* canonicalize_locale_string(const char* locale) { |
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.
is it possible to factorise it somewhere ? e.g. php_intl
Fix #11942