mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2024-11-03 01:10:17 +01:00
Fixed Html#colorsToSpan for escaped html
This commit is contained in:
parent
667dbe471f
commit
5ebe33e293
@ -96,6 +96,8 @@ public enum Html {
|
|||||||
};
|
};
|
||||||
Map<Character, String> colorMap = new HashMap<>();
|
Map<Character, String> colorMap = new HashMap<>();
|
||||||
|
|
||||||
|
String splitWith = string.contains("§") ? "§" : "§";
|
||||||
|
|
||||||
for (Html html : replacer) {
|
for (Html html : replacer) {
|
||||||
colorMap.put(Character.toLowerCase(html.name().charAt(6)), html.parse());
|
colorMap.put(Character.toLowerCase(html.name().charAt(6)), html.parse());
|
||||||
colorMap.put('k', "");
|
colorMap.put('k', "");
|
||||||
@ -106,9 +108,9 @@ public enum Html {
|
|||||||
}
|
}
|
||||||
|
|
||||||
StringBuilder result = new StringBuilder(string.length());
|
StringBuilder result = new StringBuilder(string.length());
|
||||||
String[] split = string.split("§");
|
String[] split = string.split(splitWith);
|
||||||
// Skip first part if it does not start with §
|
// Skip first part if it does not start with §
|
||||||
boolean skipFirst = !string.startsWith("§");
|
boolean skipFirst = !string.startsWith(splitWith);
|
||||||
|
|
||||||
int placedSpans = 0;
|
int placedSpans = 0;
|
||||||
for (String part : split) {
|
for (String part : split) {
|
||||||
|
@ -16,6 +16,7 @@
|
|||||||
*/
|
*/
|
||||||
package com.djrapitops.plan.utilities.html;
|
package com.djrapitops.plan.utilities.html;
|
||||||
|
|
||||||
|
import org.apache.commons.text.StringEscapeUtils;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.platform.runner.JUnitPlatform;
|
import org.junit.platform.runner.JUnitPlatform;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
@ -54,6 +55,14 @@ class HtmlTest {
|
|||||||
assertEquals(expected, result);
|
assertEquals(expected, result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void colorsToSpanSwapsEscapedHtmlColors() {
|
||||||
|
String testString = "§fHello, §aPerson§r - How Are you?";
|
||||||
|
String expected = Html.COLOR_F.parse() + "Hello, " + Html.COLOR_A.parse() + "Person</span></span> - How Are you?";
|
||||||
|
String result = Html.swapColorCodesToSpan(StringEscapeUtils.escapeHtml4(testString));
|
||||||
|
assertEquals(expected, result);
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void swapColorCodesDoesNotReplaceNonColors() {
|
void swapColorCodesDoesNotReplaceNonColors() {
|
||||||
String testString = "1test§2yes";
|
String testString = "1test§2yes";
|
||||||
|
Loading…
Reference in New Issue
Block a user