From 7188464bc1339a5af043bfffecd44210f5168ec0 Mon Sep 17 00:00:00 2001 From: John Niang Date: Mon, 30 Jan 2023 11:16:11 +0800 Subject: [PATCH] Fix the problem of slug name with percent sign when publishing post (#3179) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit #### What type of PR is this? /kind bug /area core /milestone 2.2.x #### What this PR does / why we need it: Remove URI decode operation while inserting key into RadixRouterTree to avoid repeat decode. #### Which issue(s) this PR fixes: Fixes #3178 #### Special notes for your reviewer: 1. Set slug name to `1%1` when creating a post 2. Publish it 3. Browse the post #### Does this PR introduce a user-facing change? ```release-note 修复因别名包含百分号导致无法正常访问的问题 ``` --- .../java/run/halo/app/theme/router/RadixRouterTree.java | 4 +--- .../run/halo/app/theme/router/RadixRouterTreeTest.java | 7 +++++++ 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/main/java/run/halo/app/theme/router/RadixRouterTree.java b/src/main/java/run/halo/app/theme/router/RadixRouterTree.java index 787f9be50..e6c181361 100644 --- a/src/main/java/run/halo/app/theme/router/RadixRouterTree.java +++ b/src/main/java/run/halo/app/theme/router/RadixRouterTree.java @@ -31,9 +31,7 @@ public class RadixRouterTree extends RadixTree> @Override public void insert(String key, HandlerFunction value) throws IllegalArgumentException { - // uri decode key to insert - String decodedKey = UriUtils.decode(key, StandardCharsets.UTF_8); - super.insert(decodedKey, value); + super.insert(key, value); if (log.isDebugEnabled()) { checkIndices(); } diff --git a/src/test/java/run/halo/app/theme/router/RadixRouterTreeTest.java b/src/test/java/run/halo/app/theme/router/RadixRouterTreeTest.java index 8ea5598ff..a13c767e7 100644 --- a/src/test/java/run/halo/app/theme/router/RadixRouterTreeTest.java +++ b/src/test/java/run/halo/app/theme/router/RadixRouterTreeTest.java @@ -7,6 +7,7 @@ import java.net.URISyntaxException; import org.junit.jupiter.api.Test; import org.springframework.http.HttpMethod; import org.springframework.mock.web.reactive.function.server.MockServerRequest; +import org.springframework.web.reactive.function.server.ServerResponse; /** * Tests for {@link RadixRouterTree}. @@ -41,4 +42,10 @@ class RadixRouterTreeTest { .method(HttpMethod.GET).build(); assertThat(RadixRouterTree.pathToFind(request)).isEqualTo("/?p=fake-post"); } + + @Test + void shouldInsertKeyWithPercentSign() { + var tree = new RadixRouterTree(); + tree.insert("/1%1", request -> ServerResponse.ok().build()); + } } \ No newline at end of file