From 6f849c84d4a4e9a56a4ff9be85244d804e9ac427 Mon Sep 17 00:00:00 2001 From: Yahya Erturan Date: Wed, 22 Feb 2023 07:36:44 +0300 Subject: [PATCH] mb_* functions applied Switching to mb functions to support more languages. --- src/Masked/Redact.php | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/Masked/Redact.php b/src/Masked/Redact.php index 54fb870..539c737 100644 --- a/src/Masked/Redact.php +++ b/src/Masked/Redact.php @@ -21,9 +21,9 @@ use function filter_var; use function is_callable; use function round; -use function strlen; +use function mb_strlen; use function str_repeat; -use function substr; +use function mb_substr; /** * Masks sensitive data: replaces blacklisted elements with redacted values @@ -110,14 +110,14 @@ public static function disguise($value, $unmaskedChars = 4, $maskSymbol = '*') // not enough chars to unmask ? // - if (abs($unmaskedChars) >= strlen($value)) + if (abs($unmaskedChars) >= mb_strlen($value)) { $unmaskedChars = 0; } // at least half must be masked ? // - if (abs($unmaskedChars) > strlen($value)/2) + if (abs($unmaskedChars) > mb_strlen($value)/2) { $unmaskedChars = round($unmaskedChars/2); } @@ -126,19 +126,19 @@ public static function disguise($value, $unmaskedChars = 4, $maskSymbol = '*') // if ($unmaskedChars < 0) { - $unmasked = substr($value, 0, -$unmaskedChars); + $unmasked = mb_substr($value, 0, -$unmaskedChars); return $unmasked . str_repeat($maskSymbol, - strlen($value) - strlen($unmasked) + mb_strlen($value) - mb_strlen($unmasked) ); } // trailing unmasked chars // $unmasked = $unmaskedChars - ? substr($value, -$unmaskedChars) + ? mb_substr($value, -$unmaskedChars) : ''; return str_repeat($maskSymbol, - strlen($value) - strlen($unmasked) + mb_strlen($value) - mb_strlen($unmasked) ) . $unmasked; } }