Skip to content

Commit

Permalink
Fix uncolored message stripping without validating (SkriptLang#4137)
Browse files Browse the repository at this point in the history
  • Loading branch information
AyhamAl-Ali authored Jan 17, 2022
1 parent 79b8bc4 commit 581c8a8
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions src/main/java/ch/njol/skript/util/chat/ChatMessages.java
Original file line number Diff line number Diff line change
Expand Up @@ -580,15 +580,16 @@ public static void registerAddonCode(@Nullable SkriptAddon addon, @Nullable Chat
public static String stripStyles(String text) {
List<MessageComponent> components = parse(text);
StringBuilder sb = new StringBuilder();
for (MessageComponent component : components) {
for (MessageComponent component : components) { // This also strips bracket tags ex. <red> <ttp:..> etc.
sb.append(component.text);
}
String plain = sb.toString();

// To be extra safe, strip <, >, § and &; protects against bugs in parser
if (Utils.HEX_SUPPORTED) // Strip '§x'
plain = plain.replace("§x", "");
plain = plain.replace("<", "").replace(">", "").replace("§", "").replace("&", "");

if (Utils.HEX_SUPPORTED) // Strip '§x', '&x'
plain = plain.replaceAll("[§&]x", "");

plain = plain.replaceAll("(?i)[&§][0-9a-folkrnm]", ""); // strips colors & or § (ex. &5)

assert plain != null;
return plain;
}
Expand Down

0 comments on commit 581c8a8

Please sign in to comment.