[release-2.1] Fix the problem of slug name with percent sign when publishing post (#3183)

This is an automated cherry-pick of #3179

/assign ruibaby

```release-note
修复因别名包含百分号导致无法正常访问的问题
```
pull/3417/head
Halo Dev Bot 2023-01-30 13:58:11 +08:00 committed by GitHub
parent 6dfc2f46e0
commit 2e491e025f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 3 deletions

View File

@ -31,9 +31,7 @@ public class RadixRouterTree extends RadixTree<HandlerFunction<ServerResponse>>
@Override
public void insert(String key, HandlerFunction<ServerResponse> 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();
}

View File

@ -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());
}
}