From 55ca246d3c25ffdde90547057c906486b4dd4e25 Mon Sep 17 00:00:00 2001 From: Looly Date: Tue, 18 Apr 2023 12:24:21 +0800 Subject: [PATCH] fix decode --- .../java/org/dromara/hutool/core/net/url/URLDecoder.java | 5 +++++ .../java/org/dromara/hutool/core/net/UrlDecoderTest.java | 6 ++++++ 2 files changed, 11 insertions(+) diff --git a/hutool-core/src/main/java/org/dromara/hutool/core/net/url/URLDecoder.java b/hutool-core/src/main/java/org/dromara/hutool/core/net/url/URLDecoder.java index 650b0b9e8..b1d7b8aaa 100644 --- a/hutool-core/src/main/java/org/dromara/hutool/core/net/url/URLDecoder.java +++ b/hutool-core/src/main/java/org/dromara/hutool/core/net/url/URLDecoder.java @@ -134,6 +134,11 @@ public class URLDecoder implements Serializable { char c; for (int i = 0; i < length; i++) { c = str.charAt(i); + if(CharUtil.PLUS == c){ + result.append(isPlusToSpace ? CharUtil.SPACE : c); + begin++; + continue; + } if(ESCAPE_CHAR == c || CharUtil.isHexChar(c)){ continue; } diff --git a/hutool-core/src/test/java/org/dromara/hutool/core/net/UrlDecoderTest.java b/hutool-core/src/test/java/org/dromara/hutool/core/net/UrlDecoderTest.java index 1dffef709..b47dba55f 100644 --- a/hutool-core/src/test/java/org/dromara/hutool/core/net/UrlDecoderTest.java +++ b/hutool-core/src/test/java/org/dromara/hutool/core/net/UrlDecoderTest.java @@ -16,6 +16,12 @@ public class UrlDecoderTest { Assertions.assertEquals("+", URLDecoder.decodeForPath("+", CharsetUtil.UTF_8)); } + @Test + public void decodePlusTest() { + final String decode = URLDecoder.decode("+", CharsetUtil.UTF_8); + Assertions.assertEquals(" ", decode); + } + @Test void issue3063Test() throws UnsupportedEncodingException { // https://github.com/dromara/hutool/issues/3063