Skip to content

Commit f7a1918

Browse files
committed
Allow 'h' and 'k' flags to be combined for mb_convert_kana
The 'h' flag makes mb_convert_kana convert zenkaku hiragana to hankaku katakana; 'k' makes it convert zenkaku katakana to hankaku katakana. When working on the implementation of mb_convert_kana, I added some additional checks to catch combinations of flags which do not make sense; but there is no conflict between 'h' and 'k' (they control conversions for two disjoint ranges of codepoints) and this combination should not have been restricted. Thanks to the GitHub user 'akira345' for reporting this problem. Closes GH-10174.
1 parent 07bf42d commit f7a1918

File tree

2 files changed

+3
-7
lines changed

2 files changed

+3
-7
lines changed

ext/mbstring/mbstring.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3185,10 +3185,7 @@ PHP_FUNCTION(mb_convert_kana)
31853185
* or all FW hiragana to FW katakana, or all FW katakana to FW hiragana, but not
31863186
* more than one of these */
31873187
if (opt & MBFL_ZEN2HAN_HIRAGANA) {
3188-
if (opt & MBFL_ZEN2HAN_KATAKANA) {
3189-
zend_argument_value_error(2, "must not combine 'h' and 'k' flags");
3190-
RETURN_THROWS();
3191-
} else if (opt & MBFL_ZENKAKU_HIRA2KATA) {
3188+
if (opt & MBFL_ZENKAKU_HIRA2KATA) {
31923189
zend_argument_value_error(2, "must not combine 'h' and 'C' flags");
31933190
RETURN_THROWS();
31943191
} else if (opt & MBFL_ZENKAKU_KATA2HIRA) {

ext/mbstring/tests/mb_convert_kana.phpt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ echo bin2hex(mb_convert_kana("\x30\x9B", 'k', 'UTF-16BE')), "\n";
7878
echo bin2hex(mb_convert_kana("\x30\x9C", 'k', 'UTF-16BE')), "\n";
7979
echo bin2hex(mb_convert_kana("\x30\xFC", 'k', 'UTF-16BE')), "\n";
8080
echo bin2hex(mb_convert_kana("\x30\xFB", 'k', 'UTF-16BE')), "\n";
81+
echo bin2hex(mb_convert_kana("fooあいうエオ", "rnaskh", "UTF-8")), "\n";
8182
echo "Including one which will expand to two codepoints:\n";
8283
echo bin2hex(mb_convert_kana("\x30\x52", 'h', 'UTF-16BE')), "\n\n";
8384

@@ -117,7 +118,6 @@ tryIncompatibleFlags('R', 'r');
117118
tryIncompatibleFlags('N', 'n');
118119
tryIncompatibleFlags('S', 's');
119120
tryIncompatibleFlags('K', 'H');
120-
tryIncompatibleFlags('k', 'h');
121121
tryIncompatibleFlags('C', 'c');
122122
tryIncompatibleFlags('M', 'm');
123123
tryIncompatibleFlags('h', 'C');
@@ -204,6 +204,7 @@ ff9e
204204
ff9f
205205
ff70
206206
ff65
207+
666f6fefbdb1efbdb2efbdb3efbdb4efbdb5
207208
Including one which will expand to two codepoints:
208209
ff79ff9e
209210

@@ -237,8 +238,6 @@ mb_convert_kana(): Argument #2 ($mode) must not combine 'S' and 's' flags
237238
mb_convert_kana(): Argument #2 ($mode) must not combine 'S' and 's' flags
238239
mb_convert_kana(): Argument #2 ($mode) must not combine 'H' and 'K' flags
239240
mb_convert_kana(): Argument #2 ($mode) must not combine 'H' and 'K' flags
240-
mb_convert_kana(): Argument #2 ($mode) must not combine 'h' and 'k' flags
241-
mb_convert_kana(): Argument #2 ($mode) must not combine 'h' and 'k' flags
242241
mb_convert_kana(): Argument #2 ($mode) must not combine 'C' and 'c' flags
243242
mb_convert_kana(): Argument #2 ($mode) must not combine 'C' and 'c' flags
244243
mb_convert_kana(): Argument #2 ($mode) must not combine 'M' and 'm' flags

0 commit comments

Comments
 (0)