Skip to content

Commit b215d13

Browse files
committed
Merge branch 'PHP-7.2' into PHP-7.3
* PHP-7.2: Fix #77937: preg_match failed
2 parents a0749fe + f3ff72e commit b215d13

File tree

3 files changed

+47
-0
lines changed

3 files changed

+47
-0
lines changed

NEWS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ PHP NEWS
4242
- Standard:
4343
. Fixed bug #77135 (Extract with EXTR_SKIP should skip $this).
4444
(Craig Duncan, Dmitry)
45+
. Fixed bug ##77937 (preg_match failed). (cmb, Anatol)
4546

4647
- Zip:
4748
. Fixed bug #76345 (zip.h not found). (Michael Maroszek)

ext/standard/string.c

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4852,7 +4852,28 @@ PHP_FUNCTION(setlocale)
48524852
}
48534853
}
48544854

4855+
# ifndef PHP_WIN32
48554856
retval = php_my_setlocale(cat, loc ? ZSTR_VAL(loc) : NULL);
4857+
# else
4858+
if (loc) {
4859+
/* BC: don't try /^[a-z]{2}_[A-Z]{2}($|\..*)/ except for /^u[ks]_U[KS]$/ */
4860+
char *locp = ZSTR_VAL(loc);
4861+
if (ZSTR_LEN(loc) >= 5 && locp[2] == '_'
4862+
&& locp[0] >= 'a' && locp[0] <= 'z' && locp[1] >= 'a' && locp[1] <= 'z'
4863+
&& locp[3] >= 'A' && locp[3] <= 'Z' && locp[4] >= 'A' && locp[4] <= 'Z'
4864+
&& (locp[5] == '\0' || locp[5] == '.')
4865+
&& !(locp[0] == 'u' && (locp[1] == 'k' || locp[1] == 's')
4866+
&& locp[3] == 'U' && (locp[4] == 'K' || locp[4] == 'S')
4867+
&& locp[5] == '\0')
4868+
) {
4869+
retval = NULL;
4870+
} else {
4871+
retval = php_my_setlocale(cat, ZSTR_VAL(loc));
4872+
}
4873+
} else {
4874+
retval = php_my_setlocale(cat, NULL);
4875+
}
4876+
# endif
48564877
zend_update_current_locale();
48574878
if (retval) {
48584879
if (loc) {
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
--TEST--
2+
Unix locale names are rejected on Windows, except for some special cases
3+
--SKIPIF--
4+
<?php
5+
if (substr(PHP_OS, 0, 3) != 'WIN') die('skip this test is for Windows platforms only');
6+
?>
7+
--FILE--
8+
<?php
9+
var_dump(setlocale(LC_ALL, 'de_DE'));
10+
var_dump(setlocale(LC_ALL, 'de_DE.UTF-8'));
11+
// the following are supposed to be accepted
12+
var_dump(setlocale(LC_ALL, 'uk_UK'));
13+
var_dump(setlocale(LC_ALL, 'uk_US'));
14+
var_dump(setlocale(LC_ALL, 'us_UK'));
15+
var_dump(setlocale(LC_ALL, 'us_US'));
16+
?>
17+
===DONE===
18+
--EXPECT--
19+
bool(false)
20+
bool(false)
21+
string(27) "English_United Kingdom.1252"
22+
string(26) "English_United States.1252"
23+
string(27) "English_United Kingdom.1252"
24+
string(26) "English_United States.1252"
25+
===DONE===

0 commit comments

Comments
 (0)