Skip to content

Commit 6419e74

Browse files
committed
fix: replace deprecated URLDecoder method with charset specification
Signed-off-by: Zhiwei Liang <zhiwei.liang@zliang.me>
1 parent 30d353d commit 6419e74

1 file changed

Lines changed: 9 additions & 4 deletions

File tree

  • modules/swagger-codegen/src/main/java/io/swagger/codegen/v3/auth

modules/swagger-codegen/src/main/java/io/swagger/codegen/v3/auth/AuthParser.java

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@
44
import org.slf4j.Logger;
55
import org.slf4j.LoggerFactory;
66

7+
import java.io.UnsupportedEncodingException;
78
import java.net.URLDecoder;
89
import java.net.URLEncoder;
10+
import java.nio.charset.StandardCharsets;
911
import java.util.ArrayList;
1012
import java.util.List;
1113

@@ -22,8 +24,11 @@ public static List<AuthorizationValue> parse(String urlEncodedAuthStr) {
2224
for (String part : parts) {
2325
String[] kvPair = part.split(":");
2426
if (kvPair.length == 2) {
25-
// FIXME replace the deprecated method by decode(string, encoding). Which encoding is used ? Default UTF-8 ?
26-
auths.add(new AuthorizationValue(URLDecoder.decode(kvPair[0]), URLDecoder.decode(kvPair[1]), "header"));
27+
try {
28+
auths.add(new AuthorizationValue(URLDecoder.decode(kvPair[0], StandardCharsets.UTF_8.name()), URLDecoder.decode(kvPair[1], StandardCharsets.UTF_8.name()), "header"));
29+
} catch (UnsupportedEncodingException e) {
30+
throw new AssertionError("UTF-8 is not supported", e);
31+
}
2732
}
2833
}
2934
}
@@ -38,9 +43,9 @@ public static String reconstruct(List<AuthorizationValue> authorizationValueList
3843
if (b.toString().length() > 0) {
3944
b.append(",");
4045
}
41-
b.append(URLEncoder.encode(v.getKeyName(), "UTF-8"))
46+
b.append(URLEncoder.encode(v.getKeyName(), StandardCharsets.UTF_8.name()))
4247
.append(":")
43-
.append(URLEncoder.encode(v.getValue(), "UTF-8"));
48+
.append(URLEncoder.encode(v.getValue(), StandardCharsets.UTF_8.name()));
4449
} catch (Exception e) {
4550
// continue
4651
LOGGER.error(e.getMessage(), e);

0 commit comments

Comments
 (0)