-
Notifications
You must be signed in to change notification settings - Fork 8.1k
Add Locale::getDisplayKeyword() and Locale::getDisplayKeywordValue() #22264
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
Changes from 10 commits
cb244e3
2b0d787
a3097f1
9a9348e
37d515e
053f749
1ab6deb
247501e
0340d9c
28f8b6b
6053116
793bc58
70383dc
dcc5543
42e5f8c
4632f47
df63024
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| --TEST-- | ||
| locale_get_display_keyword() basic | ||
| --EXTENSIONS-- | ||
| intl | ||
| --FILE-- | ||
| <?php | ||
|
|
||
| function ut_main() | ||
| { | ||
| $default = ut_loc_get_default(); | ||
| ut_loc_set_default('en'); | ||
|
|
||
| $keyword = ut_loc_get_display_keyword('calendar', 'en'); | ||
| var_dump($keyword); | ||
| var_dump(ut_loc_get_display_keyword('calendar', null) === $keyword); | ||
|
|
||
| $keywordValue = ut_loc_get_display_keyword_value('de_DE@calendar=gregorian', 'calendar', 'en'); | ||
| var_dump($keywordValue); | ||
| var_dump(ut_loc_get_display_keyword_value('de_DE@calendar=gregorian', 'calendar', null) === $keywordValue); | ||
|
|
||
| $collationValue = ut_loc_get_display_keyword_value('de_DE@collation=phonebook', 'collation', 'en'); | ||
| var_dump($collationValue); | ||
|
|
||
| ut_loc_set_default($default); | ||
| } | ||
|
|
||
| include_once 'ut_common.inc'; | ||
| ut_run(); | ||
| ?> | ||
| --EXPECTREGEX-- | ||
| string\([1-9][0-9]*\) "[^"\n]+" | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I meant ; there is probably a safe subset of characters to expect within a value ?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see. "[A-Za-z]+( [A-Za-z]+)*" should be safer but it could only test the spaces 🤔
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. not quite what I had in mind, e.g. previously was hardcoded "Gregorian Calendar", it might be safe to assume "Gregorian" token is going to be a safe assumption |
||
| bool(true) | ||
| string\([1-9][0-9]*\) "[^"\n]+" | ||
| bool(true) | ||
| string\([1-9][0-9]*\) "[^"\n]+" | ||
| string\([1-9][0-9]*\) "[^"\n]+" | ||
| bool(true) | ||
| string\([1-9][0-9]*\) "[^"\n]+" | ||
| bool(true) | ||
| string\([1-9][0-9]*\) "[^"\n]+" | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| --TEST-- | ||
| locale_get_display_keyword_value() error path | ||
| --EXTENSIONS-- | ||
| intl | ||
| --FILE-- | ||
| <?php | ||
|
|
||
| $locale = str_repeat('*', 256); | ||
|
|
||
| var_dump(Locale::getDisplayKeywordValue($locale, 'calendar', 'en')); | ||
| var_dump(intl_get_error_message()); | ||
| var_dump(locale_get_display_keyword_value($locale, 'calendar', 'en')); | ||
| var_dump(intl_get_error_message()); | ||
|
|
||
| ?> | ||
| --EXPECT-- | ||
| bool(false) | ||
| string(73) "Locale::getDisplayKeywordValue(): name too long: U_ILLEGAL_ARGUMENT_ERROR" | ||
| bool(false) | ||
| string(75) "locale_get_display_keyword_value(): name too long: U_ILLEGAL_ARGUMENT_ERROR" |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| --TEST-- | ||
| locale_get_display_keyword() throwing null bytes exceptions. | ||
| --EXTENSIONS-- | ||
| intl | ||
| --FILE-- | ||
| <?php | ||
|
|
||
| function ut_main() | ||
| { | ||
| $calls = [ | ||
| fn() => ut_loc_get_display_keyword("cur\0rency", "fr"), | ||
| fn() => ut_loc_get_display_keyword("currency", "f\0r"), | ||
| fn() => ut_loc_get_display_keyword_value("de_DE@calendar=gregorian\0", "calendar", "en"), | ||
| fn() => ut_loc_get_display_keyword_value("de_DE@calendar=gregorian", "cal\0endar", "en"), | ||
| fn() => ut_loc_get_display_keyword_value("de_DE@calendar=gregorian", "calendar", "e\0n"), | ||
| ]; | ||
|
|
||
| foreach ($calls as $call) { | ||
| try { | ||
| $call(); | ||
| } catch (\ValueError $e) { | ||
| echo $e->getMessage(), PHP_EOL; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| include_once 'ut_common.inc'; | ||
| ut_run(); | ||
| ?> | ||
| --EXPECT-- | ||
| Locale::getDisplayKeyword(): Argument #1 ($keyword) must not contain any null bytes | ||
| Locale::getDisplayKeyword(): Argument #2 ($displayLocale) must not contain any null bytes | ||
| Locale::getDisplayKeywordValue(): Argument #1 ($locale) must not contain any null bytes | ||
| Locale::getDisplayKeywordValue(): Argument #2 ($keyword) must not contain any null bytes | ||
| Locale::getDisplayKeywordValue(): Argument #3 ($displayLocale) must not contain any null bytes | ||
| locale_get_display_keyword(): Argument #1 ($keyword) must not contain any null bytes | ||
| locale_get_display_keyword(): Argument #2 ($displayLocale) must not contain any null bytes | ||
| locale_get_display_keyword_value(): Argument #1 ($locale) must not contain any null bytes | ||
| locale_get_display_keyword_value(): Argument #2 ($keyword) must not contain any null bytes | ||
| locale_get_display_keyword_value(): Argument #3 ($displayLocale) must not contain any null bytes |
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:
loc_nameis bounded butkeyword_nameis not, in either branch. Unlike the locale-name overflow (bug 67397),uloc_getDisplayKeyword{,Value}grows the output buffer in the loop and echoes unknown keywords back, so I do not think an overlong keyword can crash. Noting it for symmetry; fine to leave as-is.