Skip to content

Commit

Permalink
Allow 'h' and 'k' flags to be combined for mb_convert_kana
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
alexdowad committed Dec 29, 2022
1 parent 07bf42d commit f7a1918
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 7 deletions.
5 changes: 1 addition & 4 deletions ext/mbstring/mbstring.c
Expand Up @@ -3185,10 +3185,7 @@ PHP_FUNCTION(mb_convert_kana)
* or all FW hiragana to FW katakana, or all FW katakana to FW hiragana, but not
* more than one of these */
if (opt & MBFL_ZEN2HAN_HIRAGANA) {
if (opt & MBFL_ZEN2HAN_KATAKANA) {
zend_argument_value_error(2, "must not combine 'h' and 'k' flags");
RETURN_THROWS();
} else if (opt & MBFL_ZENKAKU_HIRA2KATA) {
if (opt & MBFL_ZENKAKU_HIRA2KATA) {
zend_argument_value_error(2, "must not combine 'h' and 'C' flags");
RETURN_THROWS();
} else if (opt & MBFL_ZENKAKU_KATA2HIRA) {
Expand Down
5 changes: 2 additions & 3 deletions ext/mbstring/tests/mb_convert_kana.phpt
Expand Up @@ -78,6 +78,7 @@ echo bin2hex(mb_convert_kana("\x30\x9B", 'k', 'UTF-16BE')), "\n";
echo bin2hex(mb_convert_kana("\x30\x9C", 'k', 'UTF-16BE')), "\n";
echo bin2hex(mb_convert_kana("\x30\xFC", 'k', 'UTF-16BE')), "\n";
echo bin2hex(mb_convert_kana("\x30\xFB", 'k', 'UTF-16BE')), "\n";
echo bin2hex(mb_convert_kana("fooあいうエオ", "rnaskh", "UTF-8")), "\n";
echo "Including one which will expand to two codepoints:\n";
echo bin2hex(mb_convert_kana("\x30\x52", 'h', 'UTF-16BE')), "\n\n";

Expand Down Expand Up @@ -117,7 +118,6 @@ tryIncompatibleFlags('R', 'r');
tryIncompatibleFlags('N', 'n');
tryIncompatibleFlags('S', 's');
tryIncompatibleFlags('K', 'H');
tryIncompatibleFlags('k', 'h');
tryIncompatibleFlags('C', 'c');
tryIncompatibleFlags('M', 'm');
tryIncompatibleFlags('h', 'C');
Expand Down Expand Up @@ -204,6 +204,7 @@ ff9e
ff9f
ff70
ff65
666f6fefbdb1efbdb2efbdb3efbdb4efbdb5
Including one which will expand to two codepoints:
ff79ff9e

Expand Down Expand Up @@ -237,8 +238,6 @@ mb_convert_kana(): Argument #2 ($mode) must not combine 'S' and 's' flags
mb_convert_kana(): Argument #2 ($mode) must not combine 'S' and 's' flags
mb_convert_kana(): Argument #2 ($mode) must not combine 'H' and 'K' flags
mb_convert_kana(): Argument #2 ($mode) must not combine 'H' and 'K' flags
mb_convert_kana(): Argument #2 ($mode) must not combine 'h' and 'k' flags
mb_convert_kana(): Argument #2 ($mode) must not combine 'h' and 'k' flags
mb_convert_kana(): Argument #2 ($mode) must not combine 'C' and 'c' flags
mb_convert_kana(): Argument #2 ($mode) must not combine 'C' and 'c' flags
mb_convert_kana(): Argument #2 ($mode) must not combine 'M' and 'm' flags
Expand Down

0 comments on commit f7a1918

Please sign in to comment.