Correct error for long thing names (#12708)

Signed-off-by: Mark Herwege <mark.herwege@telenet.be>
This commit is contained in:
Mark Herwege 2022-05-09 23:05:30 +02:00 committed by GitHub
parent 888f962116
commit 9d594469df
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -46,8 +46,10 @@ public final class ElroConnectsUtil {
*/
public static String encode(String input, int length) {
byte[] bytes = input.getBytes(StandardCharsets.UTF_8);
String content = "@".repeat(length - bytes.length) + new String(bytes, StandardCharsets.UTF_8) + "$";
bytes = content.getBytes(StandardCharsets.UTF_8);
String content = "@".repeat((length > bytes.length) ? (length - bytes.length) : 0)
+ new String(bytes, StandardCharsets.UTF_8);
bytes = Arrays.copyOf(content.getBytes(StandardCharsets.UTF_8), length);
bytes[length] = (byte) "$".charAt(0);
return HexUtils.bytesToHex(bytes);
}