Browse Source

修正Xlsx的ContentType和邮箱脱敏的bug

懒得勤快 1 year ago
parent
commit
b82cc53fbb

+ 1 - 1
BenchmarkTest/BenchmarkTest.csproj

@@ -2,7 +2,7 @@
 
   <PropertyGroup>
     <OutputType>Exe</OutputType>
-    <TargetFramework>net7.0</TargetFramework>
+    <TargetFramework>net8.0</TargetFramework>
     <ImplicitUsings>enable</ImplicitUsings>
   </PropertyGroup>
 

+ 1 - 1
BenchmarkTest/Program.cs

@@ -1,4 +1,4 @@
 using BenchmarkDotNet.Running;
 using BenchmarkTest;
 
-BenchmarkRunner.Run<StreamTest>();
+BenchmarkRunner.Run<TreeTest>();

+ 1 - 1
BenchmarkTest/StreamTest.cs

@@ -27,4 +27,4 @@ public class StreamTest
             stream.CopyTo(ms);
         }
     }
-}
+}

+ 110 - 0
BenchmarkTest/TreeTest.cs

@@ -0,0 +1,110 @@
+using BenchmarkDotNet.Attributes;
+using Masuit.Tools.Models;
+
+namespace BenchmarkTest;
+
+[MemoryDiagnoser]
+public class TreeTest
+{
+    public List<MyClass> Tree { get; set; }
+    public List<MyClass> List { get; set; }
+
+    public TreeTest()
+    {
+        List = new List<MyClass>()
+        {
+            new MyClass
+            {
+                Name = "Root",
+                Id = 1
+            }
+        };
+        for (int i = 2; i < 2000; i++)
+        {
+            List.Add(new MyClass
+            {
+                Name = $"这是第{i}个子节点",
+                Id = i,
+                ParentId = (i - 1)
+            });
+        }
+
+        Tree = List.ToTree();
+    }
+
+    [Benchmark]
+    public void BuildTree()
+    {
+        _ = List.ToTree();
+    }
+
+    [Benchmark]
+    public void FilterNode()
+    {
+        var nodes = Tree.Filter(x => x.Name.Contains("514")).ToList();
+    }
+
+    [Benchmark]
+    public void FlattenNode()
+    {
+        var nodes = List[1500].Flatten().ToList();
+    }
+
+    [Benchmark]
+    public void FindRoot()
+    {
+        var root = List[1990].Root();
+    }
+
+    [Benchmark]
+    public void FindAllChildren()
+    {
+        var children = List[1990].AllChildren();
+    }
+
+    [Benchmark]
+    public void FindAllParents()
+    {
+        var children = List[1990].AllParent();
+    }
+
+    [Benchmark]
+    public void FindLevel()
+    {
+        var children = List[1990].Level();
+    }
+
+    [Benchmark]
+    public void GetPath()
+    {
+        var children = List[1990].Path();
+    }
+}
+
+public class MyClass : ITree<MyClass>, ITreeEntity<MyClass, int>
+{
+    /// <summary>
+    /// 子级
+    /// </summary>
+    public ICollection<MyClass> Children { get; set; }
+
+    /// <summary>
+    /// 主键id
+    /// </summary>
+    public int Id { get; set; }
+
+    /// <summary>
+    /// 父级id
+    /// </summary>
+    public int? ParentId { get; set; }
+
+    /// <summary>
+    /// 父节点
+    /// </summary>
+    public MyClass Parent { get; set; }
+
+    /// <summary>
+    /// 名字
+    /// </summary>
+    public string Name { get; set; }
+}

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

@@ -1,4 +1,4 @@
-using DnsClient;
+using DnsClient;
 using Masuit.Tools.DateTimeExt;
 using Masuit.Tools.Strings;
 using System;
@@ -400,7 +400,13 @@ namespace Masuit.Tools
         {
             var index = s.LastIndexOf("@");
             var oldValue = s.Substring(0, index);
-            return !MatchEmail(s).isMatch ? s : s.Replace(oldValue, Mask(oldValue, mask));
+            if (!MatchEmail(s).isMatch)
+            {
+                return s;
+            }
+
+            var newValue = Mask(oldValue, mask);
+            return newValue + s.Substring(index, s.Length - index);
         }
 
         #endregion Email

+ 2 - 2
Masuit.Tools.Abstractions/Mime/ContentType.cs

@@ -161,7 +161,7 @@ public static class ContentType
     public const string Xht = "application/xhtml+xml";
     public const string Xhtml = "application/xhtml+xml";
     public const string Xls = "application/vnd.ms-excel";
-    public const string Xlsx = "application/vnd.ms-excel";
+    public const string Xlsx = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
     public const string Xml = "application/xml";
     public const string Xpm = "image/x-xpixmap";
     public const string Xsl = "application/xml";
@@ -183,4 +183,4 @@ public static class ContentType
     public const string Zip = "application/zip";
 }
 
-#pragma warning restore 1591
+#pragma warning restore 1591

+ 1 - 1
Masuit.Tools.AspNetCore/Masuit.Tools.AspNetCore.csproj

@@ -68,7 +68,7 @@
       <PackageReference Include="System.Net.Http.Json" Version="7.0.1" />
     </ItemGroup>
     <ItemGroup Condition=" '$(TargetFramework)' == 'net8'">
-        <PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="8.0.4" />
+        <PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="8.0.5" />
       <PackageReference Include="System.Net.Http.Json" Version="8.0" />
     </ItemGroup>
 </Project>

+ 1 - 1
Masuit.Tools.Core/Masuit.Tools.Core.csproj

@@ -54,7 +54,7 @@ github:https://github.com/ldqk/Masuit.Tools
         <PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.15" />
     </ItemGroup>
     <ItemGroup Condition=" '$(TargetFramework)' == 'net8'">
-        <PackageReference Include="Microsoft.EntityFrameworkCore" Version="8.0.4" />
+        <PackageReference Include="Microsoft.EntityFrameworkCore" Version="8.0.5" />
     </ItemGroup>
     <ItemGroup>
       <Compile Remove="..\Masuit.Tools.Abstractions\Mapping\**" />

+ 1 - 1
NetCoreTest/NetCoreTest.csproj

@@ -6,7 +6,7 @@
     <ConcurrentGarbageCollection>false</ConcurrentGarbageCollection>
   </PropertyGroup>
   <ItemGroup>
-    <PackageReference Include="Swashbuckle.AspNetCore" Version="6.5.0" />
+    <PackageReference Include="Swashbuckle.AspNetCore" Version="6.6.1" />
   </ItemGroup>
   <ItemGroup>
     <Folder Include="Controllers\" />

+ 51 - 0
Test/Masuit.Tools.Abstractions.Test/Strings/StringTest.cs

@@ -0,0 +1,51 @@
+using Masuit.Tools.Strings;
+using Xunit;
+
+namespace Masuit.Tools.Abstractions.Test.Strings;
+
+public class StringTest
+{
+    [Fact]
+    public void Can_MeasureString()
+    {
+        // arrange
+        const string s = "1a啊🥳∰㍰ⅷ㍿👩‍❤️‍💋‍👩";
+
+        // act
+        var width = s.StringWidth();
+        var charCount = s.CharacterCount();
+        var bytesCount = s.BytesCount();
+        var matchEmoji = s.MatchEmoji();
+
+        // assert
+        Assert.Equal(width, 9);
+        Assert.Equal(charCount, 9);
+        Assert.Equal(bytesCount, 48);
+        Assert.True(matchEmoji);
+    }
+
+    [Fact]
+    public void Can_Mask()
+    {
+        // arrange
+        const string s = "13123456789";
+
+        // act
+        var mask = s.Mask();
+
+        // assert
+        Assert.Equal(mask, "131****6789");
+    }
+
+    [Theory]
+    [InlineData("[email protected]", "1****@1.cn")]
+    [InlineData("[email protected]", "a****@masuit.com")]
+    public void Can_MaskEmail(string input, string expect)
+    {
+        // act
+        var mask = input.MaskEmail();
+
+        // assert
+        Assert.Equal(mask, expect);
+    }
+}

+ 1 - 1
Test/Masuit.Tools.AspNetCore.ResumeFileResults.WebTest/Masuit.Tools.AspNetCore.ResumeFileResults.WebTest.csproj

@@ -23,7 +23,7 @@
   </ItemGroup>
 
   <ItemGroup>
-    <PackageReference Include="Swashbuckle.AspNetCore" Version="6.5.0" />
+    <PackageReference Include="Swashbuckle.AspNetCore" Version="6.6.1" />
   </ItemGroup>
 
   <ItemGroup>

+ 1 - 1
Test/Masuit.Tools.Core.Test/Masuit.Tools.Core.Test.csproj

@@ -9,7 +9,7 @@
   </PropertyGroup>
 
   <ItemGroup>
-    <PackageReference Include="Microsoft.AspNetCore.TestHost" Version="8.0.4" />
+    <PackageReference Include="Microsoft.AspNetCore.TestHost" Version="8.0.5" />
     <PackageReference Include="Microsoft.Extensions.Hosting" Version="8.0.0" />
     <PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.9.0" />
     <PackageReference Include="xunit" Version="2.8.0" />