| 
22 | 22 | extern "C" {  | 
23 | 23 | #include <unicode/ustring.h>  | 
24 | 24 | #include <unicode/udat.h>  | 
 | 25 | +#include <unicode/uloc.h>  | 
25 | 26 | 
 
  | 
26 | 27 | #include "php_intl.h"  | 
27 | 28 | #include "dateformat_create.h"  | 
@@ -110,7 +111,12 @@ static zend_result datefmt_ctor(INTERNAL_FUNCTION_PARAMETERS, zend_error_handlin  | 
110 | 111 | 	if (locale_len == 0) {  | 
111 | 112 | 		locale_str = (char *) intl_locale_get_default();  | 
112 | 113 | 	}  | 
113 |  | -	locale = Locale::createFromName(locale_str);  | 
 | 114 | + | 
 | 115 | +	char* canonicalized_locale = canonicalize_locale_string(locale_str);  | 
 | 116 | +	const char* final_locale = canonicalized_locale ? canonicalized_locale : locale_str;  | 
 | 117 | +	const char* stored_locale = canonicalized_locale ? canonicalized_locale : locale_str;  | 
 | 118 | + | 
 | 119 | +	locale = Locale::createFromName(final_locale);  | 
114 | 120 | 	/* get*Name accessors being set does not preclude being bogus */  | 
115 | 121 | 	if (locale.isBogus() || ((locale_len == 1 && locale_str[0] != 'C') || (locale_len > 1 && strlen(locale.getISO3Language()) == 0))) {  | 
116 | 122 |         zend_argument_value_error(1, "\"%s\" is invalid", locale_str);  | 
@@ -149,7 +155,7 @@ static zend_result datefmt_ctor(INTERNAL_FUNCTION_PARAMETERS, zend_error_handlin  | 
149 | 155 | 	}  | 
150 | 156 | 
 
  | 
151 | 157 | 	DATE_FORMAT_OBJECT(dfo) = udat_open((UDateFormatStyle)time_type,  | 
152 |  | -			(UDateFormatStyle)date_type, locale_str, NULL, 0, svalue,  | 
 | 158 | +			(UDateFormatStyle)date_type, final_locale, NULL, 0, svalue,  | 
153 | 159 | 			slength, &INTL_DATA_ERROR_CODE(dfo));  | 
154 | 160 | 
 
  | 
155 | 161 | 	if (pattern_str && pattern_str_len > 0) {  | 
@@ -182,9 +188,13 @@ static zend_result datefmt_ctor(INTERNAL_FUNCTION_PARAMETERS, zend_error_handlin  | 
182 | 188 | 	dfo->date_type			= date_type;  | 
183 | 189 | 	dfo->time_type			= time_type;  | 
184 | 190 | 	dfo->calendar			= calendar_type;  | 
185 |  | -	dfo->requested_locale	= estrdup(locale_str);  | 
 | 191 | +	/* Store the canonicalized locale, or fallback to original if canonicalization failed */  | 
 | 192 | +	dfo->requested_locale	= estrdup(stored_locale);  | 
186 | 193 | 
 
  | 
187 | 194 | error:  | 
 | 195 | +	if (canonicalized_locale) {  | 
 | 196 | +		efree(canonicalized_locale);  | 
 | 197 | +	}  | 
188 | 198 | 	if (svalue) {  | 
189 | 199 | 		efree(svalue);  | 
190 | 200 | 	}  | 
 | 
0 commit comments