String split format fix for non ascii characters
Currently just abort and return string as is
This commit is contained in:
@@ -97,7 +97,13 @@ final class CoreLibsConvertStringsTest extends TestCase
|
|||||||
'2-2',
|
'2-2',
|
||||||
null,
|
null,
|
||||||
'12--3-4'
|
'12--3-4'
|
||||||
]
|
],
|
||||||
|
'mutltibyte string' => [
|
||||||
|
'あいうえ',
|
||||||
|
'2-2',
|
||||||
|
null,
|
||||||
|
'あいうえ'
|
||||||
|
],
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -64,6 +64,13 @@ $string = '1234';
|
|||||||
print "Convert: $string with $split to: "
|
print "Convert: $string with $split to: "
|
||||||
. \CoreLibs\Convert\Strings::splitFormatString($string, $split)
|
. \CoreLibs\Convert\Strings::splitFormatString($string, $split)
|
||||||
. "<br>";
|
. "<br>";
|
||||||
|
$split = '2-2';
|
||||||
|
$string = 'あいうえ';
|
||||||
|
print "Convert: $string with $split to: "
|
||||||
|
. \CoreLibs\Convert\Strings::splitFormatString($string, $split)
|
||||||
|
. "<br>";
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// error message
|
// error message
|
||||||
print $log->printErrorMsg();
|
print $log->printErrorMsg();
|
||||||
|
|||||||
@@ -35,6 +35,14 @@ class Strings
|
|||||||
if (empty($split_format)) {
|
if (empty($split_format)) {
|
||||||
return $value;
|
return $value;
|
||||||
}
|
}
|
||||||
|
// if not in the valid ASCII character range
|
||||||
|
// might need some tweaking
|
||||||
|
if (preg_match('/[^\x20-\x7e]/', $value)) {
|
||||||
|
return $value;
|
||||||
|
}
|
||||||
|
// if (!mb_check_encoding($value, 'ASCII')) {
|
||||||
|
// return $value;
|
||||||
|
// }
|
||||||
$split_list = preg_split(
|
$split_list = preg_split(
|
||||||
// allowed split characters
|
// allowed split characters
|
||||||
"/([" . $split_charcters . "]{1})/",
|
"/([" . $split_charcters . "]{1})/",
|
||||||
|
|||||||
Reference in New Issue
Block a user