mirror of
https://github.com/GeyserMC/Geyser.git
synced 2025-12-19 14:59:27 +00:00
Fix trailing formatting characters causing OOB (#5990)
* Fix trailing formatting characters causing OOB * Fix typo
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2019-2022 GeyserMC. http://geysermc.org
|
* Copyright (c) 2019-2025 GeyserMC. http://geysermc.org
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
@@ -253,6 +253,12 @@ public class MessageTranslator {
|
|||||||
output.append(c);
|
output.append(c);
|
||||||
|
|
||||||
if (c == ChatColor.ESCAPE) {
|
if (c == ChatColor.ESCAPE) {
|
||||||
|
// If the string ends with a formatting character, remove and skip
|
||||||
|
if (i >= finalLegacyString.length() - 1) {
|
||||||
|
output = output.deleteCharAt(output.length() - 1);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
char newColor = finalLegacyString.charAt(i + 1);
|
char newColor = finalLegacyString.charAt(i + 1);
|
||||||
if (newColor == 'r') {
|
if (newColor == 'r') {
|
||||||
lastColors = new StringBuilder();
|
lastColors = new StringBuilder();
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2019-2022 GeyserMC. http://geysermc.org
|
* Copyright (c) 2019-2025 GeyserMC. http://geysermc.org
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
@@ -73,6 +73,9 @@ public class MessageTranslatorTest {
|
|||||||
messages.put("{\"translate\":\"tt{''{tt\"}", "tt{''{tt");
|
messages.put("{\"translate\":\"tt{''{tt\"}", "tt{''{tt");
|
||||||
messages.put("{\"translate\":\"tt{{''}}tt\"}", "tt{{''}}tt");
|
messages.put("{\"translate\":\"tt{{''}}tt\"}", "tt{{''}}tt");
|
||||||
|
|
||||||
|
messages.put("{\"text\":\"\",\"extra\":[{\"text\":\"Testing end of string\n formatting character§\",\"color\":\"yellow\"}]}",
|
||||||
|
"§r§eTesting end of string\n§e formatting character");
|
||||||
|
|
||||||
MessageTranslator.init();
|
MessageTranslator.init();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user