Skip to content

Conversation

alexandre-daubois
Copy link
Member

Fix #11942

@alexandre-daubois alexandre-daubois changed the base branch from master to PHP-8.3 August 26, 2025 07:22
@alexandre-daubois alexandre-daubois force-pushed the gh-11952 branch 2 times, most recently from 6caa975 to 8564487 Compare August 26, 2025 07:49
@alexandre-daubois alexandre-daubois marked this pull request as ready for review August 26, 2025 08:34
UErrorCode status = U_ZERO_ERROR;
int32_t canonicalized_len;

if (!locale || strlen(locale) == 0) {
Copy link
Member

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 ?

Copy link
Member Author

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.

Copy link
Member

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 !

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

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

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

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.

Constructors of intl extension formatter classes don't canonicalise locale strings
2 participants