Fixed color parsing eating first character

Fixes a bug where first character of
nickname or DataExtension String was
removed if it started with of 1-9, a-f & r
This commit is contained in:
Rsl1122 2019-07-28 17:53:30 +03:00
parent 710f8ec5bd
commit 8f639f7f41
2 changed files with 15 additions and 0 deletions

View File

@ -135,12 +135,19 @@ public enum Html {
StringBuilder result = new StringBuilder(string.length());
String[] split = string.split("§");
// Skip first part if it does not start with §
boolean skipFirst = !string.startsWith("§");
int placedSpans = 0;
for (String part : split) {
if (part.isEmpty()) {
continue;
}
if (skipFirst) {
result.append(part);
skipFirst = false;
continue;
}
char colorChar = part.charAt(0);
if (colorChar == 'r') {

View File

@ -53,4 +53,12 @@ class HtmlTest {
String result = Html.swapColorCodesToSpan(testString);
assertEquals(expected, result);
}
@Test
void swapColorCodesDoesNotReplaceNonColors() {
String testString = "1test§2yes";
String expected = "1test" + Html.COLOR_2.parse() + "yes</span>";
String result = Html.swapColorCodesToSpan(testString);
assertEquals(expected, result);
}
}