|
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 | goto error;
|
@@ -148,7 +154,7 @@ static zend_result datefmt_ctor(INTERNAL_FUNCTION_PARAMETERS, zend_error_handlin
|
148 | 154 | }
|
149 | 155 |
|
150 | 156 | DATE_FORMAT_OBJECT(dfo) = udat_open((UDateFormatStyle)time_type,
|
151 |
| - (UDateFormatStyle)date_type, locale_str, NULL, 0, svalue, |
| 157 | + (UDateFormatStyle)date_type, final_locale, NULL, 0, svalue, |
152 | 158 | slength, &INTL_DATA_ERROR_CODE(dfo));
|
153 | 159 |
|
154 | 160 | if (pattern_str && pattern_str_len > 0) {
|
@@ -181,9 +187,13 @@ static zend_result datefmt_ctor(INTERNAL_FUNCTION_PARAMETERS, zend_error_handlin
|
181 | 187 | dfo->date_type = date_type;
|
182 | 188 | dfo->time_type = time_type;
|
183 | 189 | dfo->calendar = calendar_type;
|
184 |
| - dfo->requested_locale = estrdup(locale_str); |
| 190 | + /* Store the canonicalized locale, or fallback to original if canonicalization failed */ |
| 191 | + dfo->requested_locale = estrdup(stored_locale); |
185 | 192 |
|
186 | 193 | error:
|
| 194 | + if (canonicalized_locale) { |
| 195 | + efree(canonicalized_locale); |
| 196 | + } |
187 | 197 | if (svalue) {
|
188 | 198 | efree(svalue);
|
189 | 199 | }
|
|
0 commit comments