This commit is contained in:
yushijinhun 2020-08-23 00:18:51 +08:00
parent 14741ad521
commit e913d7d4d4
No known key found for this signature in database
GPG Key ID: 5BC167F73EA558E4
2 changed files with 13 additions and 4 deletions

View File

@ -16,6 +16,7 @@
*/ */
package moe.yushi.authlibinjector.httpd; package moe.yushi.authlibinjector.httpd;
import static java.nio.charset.StandardCharsets.ISO_8859_1;
import static java.util.Optional.empty; import static java.util.Optional.empty;
import static java.util.Optional.of; import static java.util.Optional.of;
import static java.util.Optional.ofNullable; import static java.util.Optional.ofNullable;
@ -65,6 +66,10 @@ public class LegacySkinAPIFilter implements URLFilter {
return empty(); return empty();
String username = matcher.group("username"); String username = matcher.group("username");
// Minecraft does not encode non-ASCII characters in URLs
// We have to workaround this problem
username = correctEncoding(username);
Optional<String> skinUrl; Optional<String> skinUrl;
try { try {
skinUrl = upstream.queryUUID(username) skinUrl = upstream.queryUUID(username)
@ -104,4 +109,9 @@ public class LegacySkinAPIFilter implements URLFilter {
.map(JsonUtils::asJsonString) .map(JsonUtils::asJsonString)
.orElseThrow(() -> newUncheckedIOException("Invalid JSON: Missing texture url"))); .orElseThrow(() -> newUncheckedIOException("Invalid JSON: Missing texture url")));
} }
private static String correctEncoding(String grable) {
// platform charset is used
return new String(grable.getBytes(ISO_8859_1));
}
} }

View File

@ -46,8 +46,7 @@
*/ */
package moe.yushi.authlibinjector.internal.fi.iki.elonen; package moe.yushi.authlibinjector.internal.fi.iki.elonen;
import static java.nio.charset.StandardCharsets.US_ASCII; import static java.nio.charset.StandardCharsets.ISO_8859_1;
import java.io.BufferedInputStream; import java.io.BufferedInputStream;
import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
@ -360,7 +359,7 @@ public abstract class NanoHTTPD {
} }
// Create a BufferedReader for parsing the header. // Create a BufferedReader for parsing the header.
BufferedReader hin = new BufferedReader(new InputStreamReader(new ByteArrayInputStream(buf, 0, this.rlen), US_ASCII)); BufferedReader hin = new BufferedReader(new InputStreamReader(new ByteArrayInputStream(buf, 0, this.rlen), ISO_8859_1));
// Decode the header into parms and header java properties // Decode the header into parms and header java properties
Map<String, String> pre = new HashMap<>(); Map<String, String> pre = new HashMap<>();
@ -486,7 +485,7 @@ public abstract class NanoHTTPD {
} }
if (expect100Continue && !continueSent) { if (expect100Continue && !continueSent) {
continueSent = true; continueSent = true;
this.outputStream.write("HTTP/1.1 100 Continue\r\n\r\n".getBytes(US_ASCII)); this.outputStream.write("HTTP/1.1 100 Continue\r\n\r\n".getBytes(ISO_8859_1));
} }
} }
return this.parsedInputStream; return this.parsedInputStream;