-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Ensure ctype_string is NULL for C locale #5542
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 all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1462,7 +1462,7 @@ PHPAPI zend_string *php_string_tolower(zend_string *s) | |
unsigned char *c; | ||
const unsigned char *e; | ||
|
||
if (EXPECTED(!BG(locale_changed))) { | ||
if (EXPECTED(!BG(ctype_string))) { | ||
return zend_string_tolower(s); | ||
} else { | ||
c = (unsigned char *)ZSTR_VAL(s); | ||
|
@@ -4801,7 +4801,12 @@ PHP_FUNCTION(setlocale) | |
if (BG(ctype_string)) { | ||
zend_string_release_ex(BG(ctype_string), 0); | ||
} | ||
if (len == ZSTR_LEN(loc) && !memcmp(ZSTR_VAL(loc), retval, len)) { | ||
if (len == 1 && *retval == 'C') { | ||
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'm fairly certain that This should check ZSTR_VAL(loc) instead, e.g. 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. setlocale() returns the locale that was set, not the previous one. This is necessary because it may not be the same as what was passed to the setlocale() call, e.g. when using 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. Ok, good. I was mixed up with other C and PHP APIs that did that - the c code is returning the new locale https://en.cppreference.com/w/c/locale/setlocale |
||
/* C locale is represented as NULL. */ | ||
BG(ctype_string) = NULL; | ||
zend_string_release_ex(loc, 0); | ||
RETURN_INTERNED_STR(ZSTR_CHAR('C')); | ||
} else if (len == ZSTR_LEN(loc) && !memcmp(ZSTR_VAL(loc), retval, len)) { | ||
BG(ctype_string) = zend_string_copy(loc); | ||
RETURN_STR(BG(ctype_string)); | ||
} else { | ||
|
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.
Unrelated: What's the reasoning for performing this operation for strtolower() but not strtoupper()?
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.
Because there is no zend_string_toupper :) We only perform ASCII lowercase internally.
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.
Makes sense