Skip to content

Commit

Permalink
Partial fix for bug #69267
Browse files Browse the repository at this point in the history
This pulls in 60a25c72ba389f53b0621ca250bc99f3b295d43f from the
OpenLDAP project.
  • Loading branch information
nikic committed Jul 23, 2017
1 parent 88f752a commit 0e4af91
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 15 deletions.
27 changes: 14 additions & 13 deletions ext/mbstring/php_unicode.c
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ MBSTRING_API int php_unicode_is_prop(unsigned long code, unsigned long mask1,
static unsigned long case_lookup(unsigned long code, long l, long r, int field)
{
long m;
const unsigned int *tmp;

/*
* Do the binary search.
Expand All @@ -132,13 +133,13 @@ static unsigned long case_lookup(unsigned long code, long l, long r, int field)
* the beginning of a case mapping triple.
*/
m = (l + r) >> 1;
m -= (m % 3);
if (code > _uccase_map[m])
l = m + 3;
else if (code < _uccase_map[m])
r = m - 3;
else if (code == _uccase_map[m])
return _uccase_map[m + field];
tmp = &_uccase_map[m*3];
if (code > *tmp)
l = m + 1;
else if (code < *tmp)
r = m - 1;
else if (code == *tmp)
return tmp[field];
}

return code;
Expand Down Expand Up @@ -174,7 +175,7 @@ MBSTRING_API unsigned long php_unicode_toupper(unsigned long code, enum mbfl_no_
*/
field = 2;
l = _uccase_len[0];
r = (l + _uccase_len[1]) - 3;
r = (l + _uccase_len[1]) - 1;

if (enc == mbfl_no_encoding_8859_9) {
return php_turkish_toupper(code, l, r, field);
Expand All @@ -186,7 +187,7 @@ MBSTRING_API unsigned long php_unicode_toupper(unsigned long code, enum mbfl_no_
*/
field = 1;
l = _uccase_len[0] + _uccase_len[1];
r = _uccase_size - 3;
r = _uccase_size - 1;
}
return case_lookup(code, l, r, field);
}
Expand All @@ -205,7 +206,7 @@ MBSTRING_API unsigned long php_unicode_tolower(unsigned long code, enum mbfl_no_
*/
field = 1;
l = 0;
r = _uccase_len[0] - 3;
r = _uccase_len[0] - 1;

if (enc == mbfl_no_encoding_8859_9) {
return php_turkish_tolower(code, l, r, field);
Expand All @@ -217,7 +218,7 @@ MBSTRING_API unsigned long php_unicode_tolower(unsigned long code, enum mbfl_no_
*/
field = 2;
l = _uccase_len[0] + _uccase_len[1];
r = _uccase_size - 3;
r = _uccase_size - 1;
}
return case_lookup(code, l, r, field);
}
Expand All @@ -240,13 +241,13 @@ MBSTRING_API unsigned long php_unicode_totitle(unsigned long code, enum mbfl_no_
* The character is upper case.
*/
l = 0;
r = _uccase_len[0] - 3;
r = _uccase_len[0] - 1;
} else {
/*
* The character is lower case.
*/
l = _uccase_len[0];
r = (l + _uccase_len[1]) - 3;
r = (l + _uccase_len[1]) - 1;
}
return case_lookup(code, l, r, field);

Expand Down
9 changes: 9 additions & 0 deletions ext/mbstring/tests/bug69267.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
--TEST--
Bug #69267: mb_strtolower fails on titlecase characters
--FILE--
<?php
$str = "DžLjNjDz";
var_dump(mb_strtolower($str));
?>
--EXPECT--
string(8) "džljnjdz"
2 changes: 1 addition & 1 deletion ext/mbstring/ucgendat/ucgendat.c
Original file line number Diff line number Diff line change
Expand Up @@ -1442,7 +1442,7 @@ write_cdata(char *opath)
" * LowerIndex = _uccase_len[0]\n"
" * TitleIndex = LowerIndex + _uccase_len[1] */\n\n");
fprintf(out, PREF "unsigned short _uccase_len[2] = {%ld, %ld};\n\n",
(long) upper_used * 3, (long) lower_used * 3);
(long) upper_used, (long) lower_used);
fprintf(out, PREF "unsigned int _uccase_map[] = {");

if (upper_used > 0)
Expand Down
2 changes: 1 addition & 1 deletion ext/mbstring/unicode_data.h
Original file line number Diff line number Diff line change
Expand Up @@ -2469,7 +2469,7 @@ static const unsigned int _uccase_size = 2470;
* LowerIndex = _uccase_len[0]
* TitleIndex = LowerIndex + _uccase_len[1] */

static const unsigned short _uccase_len[2] = {3687, 3711};
static const unsigned short _uccase_len[2] = {1229, 1237};

static const unsigned int _uccase_map[] = {
0x00000041, 0x00000061, 0x00000041,
Expand Down

0 comments on commit 0e4af91

Please sign in to comment.