Browse Source

修复邮箱掩码方法的逻辑顺序问题

修复了在调用 `MatchEmail(s).isMatch` 之前对字符串 `s` 进行处理的顺序问题。原代码可能在输入无效邮箱时导致异常。调整后确保仅在邮箱格式正确时执行后续操作。
懒得勤快 3 weeks ago
parent
commit
ef4d723d44
1 changed files with 2 additions and 2 deletions
  1. 2 2
      Masuit.Tools.Abstractions/Extensions/BaseType/StringExtensions.cs

+ 2 - 2
Masuit.Tools.Abstractions/Extensions/BaseType/StringExtensions.cs

@@ -398,13 +398,13 @@ namespace Masuit.Tools
         /// <returns></returns>
         public static string MaskEmail(this string s, char mask = '*')
         {
-            var index = s.LastIndexOf("@");
-            var oldValue = s.Substring(0, index);
             if (!MatchEmail(s).isMatch)
             {
                 return s;
             }
 
+            var index = s.LastIndexOf("@");
+            var oldValue = s.Substring(0, index);
             var newValue = Mask(oldValue, mask);
             return newValue + s.Substring(index, s.Length - index);
         }