Skip to content

Commit b64048a

Browse files
Merge pull request #18 from cesarhernandezgt/v.6.0.23.RELEASE-TT.x-patch
prepare for 6.0.23.RELEASE-TT.5 release
2 parents 0184b4b + f6f6dfa commit b64048a

File tree

7 files changed

+57
-40
lines changed

7 files changed

+57
-40
lines changed

.sdkmanrc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
# Enable auto-env through the sdkman_auto_env config
22
# Add key=value pairs of SDKs to use below
3-
java=17.0.11-librca
3+
java=17.0.16-tem
4+
maven=3.9.8

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
version=6.0.23.RELEASE-TT.4
1+
version=6.0.23.RELEASE-TT.5
22

33
org.gradle.caching=true
44
org.gradle.jvmargs=-Xmx2048m

spring-core/src/main/java/org/springframework/util/StringUtils.java

Lines changed: 37 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616

1717
package org.springframework.util;
1818

19-
import java.io.ByteArrayOutputStream;
2019
import java.nio.charset.Charset;
2120
import java.util.ArrayDeque;
2221
import java.util.ArrayList;
@@ -25,6 +24,7 @@
2524
import java.util.Collections;
2625
import java.util.Deque;
2726
import java.util.Enumeration;
27+
import java.util.HexFormat;
2828
import java.util.Iterator;
2929
import java.util.LinkedHashSet;
3030
import java.util.List;
@@ -785,54 +785,60 @@ public static boolean pathEquals(String path1, String path2) {
785785
}
786786

787787
/**
788-
* Decode the given encoded URI component value. Based on the following rules:
789-
* <ul>
790-
* <li>Alphanumeric characters {@code "a"} through {@code "z"}, {@code "A"} through {@code "Z"},
791-
* and {@code "0"} through {@code "9"} stay the same.</li>
792-
* <li>Special characters {@code "-"}, {@code "_"}, {@code "."}, and {@code "*"} stay the same.</li>
793-
* <li>A sequence "{@code %<i>xy</i>}" is interpreted as a hexadecimal representation of the character.</li>
794-
* <li>For all other characters (including those already decoded), the output is undefined.</li>
795-
* </ul>
796-
* @param source the encoded String
797-
* @param charset the character set
788+
* Decode the given encoded URI component value by replacing "<i>{@code %xy}</i>" sequences
789+
* by an hexadecimal representation of the character in the specified charset, letting other
790+
* characters unchanged.
791+
* @param source the encoded {@code String}
792+
* @param charset the character encoding to use to decode the "<i>{@code %xy}</i>" sequences
798793
* @return the decoded value
799794
* @throws IllegalArgumentException when the given source contains invalid encoded sequences
800795
* @since 5.0
801-
* @see java.net.URLDecoder#decode(String, String)
796+
* @see java.net.URLDecoder#decode(String, String) java.net.URLDecoder#decode for HTML form decoding
802797
*/
803798
public static String uriDecode(String source, Charset charset) {
804799
int length = source.length();
805-
if (length == 0) {
800+
int firstPercentIndex = source.indexOf('%');
801+
if (length == 0 || firstPercentIndex < 0) {
806802
return source;
807803
}
808-
Assert.notNull(charset, "Charset must not be null");
809804

810-
ByteArrayOutputStream baos = new ByteArrayOutputStream(length);
811-
boolean changed = false;
812-
for (int i = 0; i < length; i++) {
813-
int ch = source.charAt(i);
805+
StringBuilder output = new StringBuilder(length);
806+
output.append(source, 0, firstPercentIndex);
807+
byte[] bytes = null;
808+
int i = firstPercentIndex;
809+
while (i < length) {
810+
char ch = source.charAt(i);
814811
if (ch == '%') {
815-
if (i + 2 < length) {
816-
char hex1 = source.charAt(i + 1);
817-
char hex2 = source.charAt(i + 2);
818-
int u = Character.digit(hex1, 16);
819-
int l = Character.digit(hex2, 16);
820-
if (u == -1 || l == -1) {
821-
throw new IllegalArgumentException("Invalid encoded sequence \"" + source.substring(i) + "\"");
812+
try {
813+
if (bytes == null) {
814+
bytes = new byte[(length - i) / 3];
822815
}
823-
baos.write((char) ((u << 4) + l));
824-
i += 2;
825-
changed = true;
816+
817+
int pos = 0;
818+
while (i + 2 < length && ch == '%') {
819+
bytes[pos++] = (byte) HexFormat.fromHexDigits(source, i + 1, i + 3);
820+
i += 3;
821+
if (i < length) {
822+
ch = source.charAt(i);
823+
}
824+
}
825+
826+
if (i < length && ch == '%') {
827+
throw new IllegalArgumentException("Incomplete trailing escape (%) pattern");
828+
}
829+
830+
output.append(new String(bytes, 0, pos, charset));
826831
}
827-
else {
832+
catch (NumberFormatException ex) {
828833
throw new IllegalArgumentException("Invalid encoded sequence \"" + source.substring(i) + "\"");
829834
}
830835
}
831836
else {
832-
baos.write(ch);
837+
output.append(ch);
838+
i++;
833839
}
834840
}
835-
return (changed ? StreamUtils.copyToString(baos, charset) : source);
841+
return output.toString();
836842
}
837843

838844
/**

spring-web/src/main/java/org/springframework/web/util/UriUtils.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -373,15 +373,16 @@ public static String decode(String source, String encoding) {
373373
}
374374

375375
/**
376-
* Decode the given encoded URI component.
377-
* <p>See {@link StringUtils#uriDecode(String, Charset)} for the decoding rules.
378-
* @param source the encoded String
379-
* @param charset the character encoding to use
376+
* Decode the given encoded URI component value by replacing "<i>{@code %xy}</i>" sequences
377+
* by an hexadecimal representation of the character in the specified charset, letting other
378+
* characters unchanged.
379+
* @param source the encoded {@code String}
380+
* @param charset the character encoding to use to decode the "<i>{@code %xy}</i>" sequences
380381
* @return the decoded value
381382
* @throws IllegalArgumentException when the given source contains invalid encoded sequences
382383
* @since 5.0
383384
* @see StringUtils#uriDecode(String, Charset)
384-
* @see java.net.URLDecoder#decode(String, String)
385+
* @see java.net.URLDecoder#decode(String, String) java.net.URLDecoder#decode for HTML form decoding
385386
*/
386387
public static String decode(String source, Charset charset) {
387388
return StringUtils.uriDecode(source, charset);

spring-web/src/test/java/org/springframework/web/util/UriUtilsTests.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,12 +107,21 @@ public void decode() {
107107
assertThat(UriUtils.decode("T%C5%8Dky%C5%8D", CHARSET)).as("Invalid encoded result").isEqualTo("T\u014dky\u014d");
108108
assertThat(UriUtils.decode("/Z%C3%BCrich", CHARSET)).as("Invalid encoded result").isEqualTo("/Z\u00fcrich");
109109
assertThat(UriUtils.decode("T\u014dky\u014d", CHARSET)).as("Invalid encoded result").isEqualTo("T\u014dky\u014d");
110+
assertThat(UriUtils.decode("%20\u2019", CHARSET)).as("Invalid encoded result").isEqualTo(" \u2019");
111+
assertThat(UriUtils.decode("\u015bp\u0159\u00ec\u0144\u0121", CHARSET)).as("Invalid encoded result").isEqualTo("śpřìńġ");
112+
assertThat(UriUtils.decode("%20\u015bp\u0159\u00ec\u0144\u0121", CHARSET)).as("Invalid encoded result").isEqualTo(" śpřìńġ");
110113
}
111114

112115
@Test
113116
public void decodeInvalidSequence() {
114117
assertThatIllegalArgumentException().isThrownBy(() ->
115118
UriUtils.decode("foo%2", CHARSET));
119+
assertThatIllegalArgumentException().isThrownBy(() ->
120+
UriUtils.decode("foo%", CHARSET));
121+
assertThatIllegalArgumentException().isThrownBy(() ->
122+
UriUtils.decode("%", CHARSET));
123+
assertThatIllegalArgumentException().isThrownBy(() ->
124+
UriUtils.decode("%zz", CHARSET));
116125
}
117126

118127
@Test

spring-webflux/src/test/resources/org/springframework/web/reactive/result/view/freemarker/test-macro.ftl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ NAME
77
${command.name}
88

99
AGE
10-
${command.age}
10+
${command.age()}
1111

1212
MESSAGE
1313
<@spring.message "hello"/> <@spring.message "world"/>

spring-webmvc/src/test/resources/org/springframework/web/servlet/view/freemarker/test.ftl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ NAME
77
${command.name}
88

99
AGE
10-
${command.age}
10+
${command.age()}
1111

1212
MESSAGE
1313
<@spring.message "hello"/> <@spring.message "world"/>

0 commit comments

Comments
 (0)