Skip to content

Commit

Permalink
Merge pull request #6 from xxxxue/fix_ReplaceSpace
Browse files Browse the repository at this point in the history
fix: 修复 ReplaceSpace 正则语法的 bug
  • Loading branch information
xxxxue authored Jun 15, 2023
2 parents cf4e368 + 6436094 commit f58c47c
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 6 deletions.
12 changes: 9 additions & 3 deletions DocsifyBuildSidebar.sln
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.30717.126
# Visual Studio Version 17
VisualStudioVersion = 17.5.33516.290
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DocsifyBuildSidebar", "DocsifyBuildSidebar\DocsifyBuildSidebar.csproj", "{7B85196D-D0E6-4724-BF44-1FA2917797B5}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DocsifyBuildSidebar", "DocsifyBuildSidebar\DocsifyBuildSidebar.csproj", "{7B85196D-D0E6-4724-BF44-1FA2917797B5}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DocsifyBuildSidebarTests", "DocsifyBuildSidebarTests\DocsifyBuildSidebarTests.csproj", "{D4C87DBB-8C34-4B9A-90D6-EF00911C759E}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand All @@ -15,6 +17,10 @@ Global
{7B85196D-D0E6-4724-BF44-1FA2917797B5}.Debug|Any CPU.Build.0 = Debug|Any CPU
{7B85196D-D0E6-4724-BF44-1FA2917797B5}.Release|Any CPU.ActiveCfg = Release|Any CPU
{7B85196D-D0E6-4724-BF44-1FA2917797B5}.Release|Any CPU.Build.0 = Release|Any CPU
{D4C87DBB-8C34-4B9A-90D6-EF00911C759E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{D4C87DBB-8C34-4B9A-90D6-EF00911C759E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D4C87DBB-8C34-4B9A-90D6-EF00911C759E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D4C87DBB-8C34-4B9A-90D6-EF00911C759E}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
6 changes: 3 additions & 3 deletions DocsifyBuildSidebar/Utils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public static string GenerateSpace(int n)
/// <returns></returns>
public static string ReplaceSpace(string data)
{
return Regex.Replace(data, @"/\s{1,1}/g", "%20");
return Regex.Replace(data, @"\s{1,1}", "%20");
}

/// <summary>
Expand All @@ -61,7 +61,7 @@ public static string ReplaceSpace(string data)
/// <returns></returns>
public static string GetFileNameWithoutExtension(this FileInfo file)
{
return file.Name.Replace(file.Extension, "");
return Path.GetFileNameWithoutExtension(file.Name);
}

/// <summary>
Expand All @@ -71,7 +71,7 @@ public static string GetFileNameWithoutExtension(this FileInfo file)
/// <returns></returns>
public static string GetFileRelativePath(this FileInfo file)
{
return file.FullName.Replace(GetCurrentDirectory(), "").TrimStart('\\').Replace("\\", "/");
return file.FullName.Replace(GetCurrentDirectory(), "").TrimStart('\\').Replace("\\", "/");
}

/// <summary>
Expand Down
29 changes: 29 additions & 0 deletions DocsifyBuildSidebarTests/DocsifyBuildSidebarTests.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>

<IsPackable>false</IsPackable>
<IsTestProject>true</IsTestProject>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.3.2" />
<PackageReference Include="xunit" Version="2.4.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="coverlet.collector" Version="3.1.2">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\DocsifyBuildSidebar\DocsifyBuildSidebar.csproj" />
</ItemGroup>

</Project>
1 change: 1 addition & 0 deletions DocsifyBuildSidebarTests/Usings.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
global using Xunit;
33 changes: 33 additions & 0 deletions DocsifyBuildSidebarTests/UtilsTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
using DocsifyBuildSidebar;

using Xunit.Abstractions;

namespace DocsifyBuildSidebarTests
{
public class UtilsTests
{

public ITestOutputHelper Log { get; set; }
public UtilsTests(ITestOutputHelper log)
{
Log = log;
}

[Fact]
public void Test_GenerateSpace()
{

Assert.Equal(" ", Utils.GenerateSpace(1));
Assert.Equal(" ", Utils.GenerateSpace(2));
Assert.Equal(" ", Utils.GenerateSpace(3));
}

[Fact]
public void Test_ReplaceSpace()
{
var res = Utils.ReplaceSpace("测试数据 嘿嘿嘿 按按 问问");
Assert.Equal("测试数据%20嘿嘿嘿%20按按%20问问", res);
}

}
}

0 comments on commit f58c47c

Please sign in to comment.