|
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" |
@@ -106,7 +107,12 @@ static zend_result datefmt_ctor(INTERNAL_FUNCTION_PARAMETERS) |
106 | 107 | if (locale_len == 0) { |
107 | 108 | locale_str = (char *) intl_locale_get_default(); |
108 | 109 | } |
109 | | - locale = Locale::createFromName(locale_str); |
| 110 | + |
| 111 | + char* canonicalized_locale = canonicalize_locale_string(locale_str); |
| 112 | + const char* final_locale = canonicalized_locale ? canonicalized_locale : locale_str; |
| 113 | + const char* stored_locale = canonicalized_locale ? canonicalized_locale : locale_str; |
| 114 | + |
| 115 | + locale = Locale::createFromName(final_locale); |
110 | 116 | /* get*Name accessors being set does not preclude being bogus */ |
111 | 117 | if (locale.isBogus() || ((locale_len == 1 && locale_str[0] != 'C') || (locale_len > 1 && strlen(locale.getISO3Language()) == 0))) { |
112 | 118 | zend_argument_value_error(1, "\"%s\" is invalid", locale_str); |
@@ -144,7 +150,7 @@ static zend_result datefmt_ctor(INTERNAL_FUNCTION_PARAMETERS) |
144 | 150 | } |
145 | 151 |
|
146 | 152 | DATE_FORMAT_OBJECT(dfo) = udat_open((UDateFormatStyle)time_type, |
147 | | - (UDateFormatStyle)date_type, locale_str, NULL, 0, svalue, |
| 153 | + (UDateFormatStyle)date_type, final_locale, NULL, 0, svalue, |
148 | 154 | slength, &INTL_DATA_ERROR_CODE(dfo)); |
149 | 155 |
|
150 | 156 | if (pattern_str && pattern_str_len > 0) { |
@@ -176,9 +182,13 @@ static zend_result datefmt_ctor(INTERNAL_FUNCTION_PARAMETERS) |
176 | 182 | dfo->date_type = date_type; |
177 | 183 | dfo->time_type = time_type; |
178 | 184 | dfo->calendar = calendar_type; |
179 | | - dfo->requested_locale = estrdup(locale_str); |
| 185 | + /* Store the canonicalized locale, or fallback to original if canonicalization failed */ |
| 186 | + dfo->requested_locale = estrdup(stored_locale); |
180 | 187 |
|
181 | 188 | error: |
| 189 | + if (canonicalized_locale) { |
| 190 | + efree(canonicalized_locale); |
| 191 | + } |
182 | 192 | if (svalue) { |
183 | 193 | efree(svalue); |
184 | 194 | } |
|
0 commit comments