add sanitize junit test to test coveralls
This commit is contained in:
parent
0e7a6e58e2
commit
b0951d7427
|
@ -2,6 +2,7 @@ package me.oskar3123.staffchat.bungee.listener;
|
|||
|
||||
import me.oskar3123.staffchat.bungee.BungeeMain;
|
||||
import me.oskar3123.staffchat.bungee.event.BungeeStaffChatEvent;
|
||||
import me.oskar3123.staffchat.util.StringUtils;
|
||||
import net.md_5.bungee.api.ChatColor;
|
||||
import net.md_5.bungee.api.chat.BaseComponent;
|
||||
import net.md_5.bungee.api.chat.TextComponent;
|
||||
|
@ -53,8 +54,8 @@ public class BungeeChatListener implements Listener
|
|||
}
|
||||
format = chatEvent.getFormat();
|
||||
|
||||
format = format.replaceAll("\\{NAME\\}", sanitize(player.getName()));
|
||||
format = format.replaceAll("\\{MESSAGE\\}", sanitize(message));
|
||||
format = format.replaceAll("\\{NAME\\}", StringUtils.sanitize(player.getName()));
|
||||
format = format.replaceAll("\\{MESSAGE\\}", StringUtils.sanitize(message));
|
||||
final BaseComponent[] messageComponents = txt(format);
|
||||
|
||||
plugin.getProxy().getPlayers().stream()
|
||||
|
@ -75,11 +76,4 @@ public class BungeeChatListener implements Listener
|
|||
return TextComponent.fromLegacyText(clr(text));
|
||||
}
|
||||
|
||||
private String sanitize(String string)
|
||||
{
|
||||
string = string.replaceAll("\\\\", "\\\\\\\\");
|
||||
string = string.replaceAll("\\$", "\\\\\\$");
|
||||
return string;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@ package me.oskar3123.staffchat.spigot.listener;
|
|||
|
||||
import me.oskar3123.staffchat.spigot.Main;
|
||||
import me.oskar3123.staffchat.spigot.event.StaffChatEvent;
|
||||
import me.oskar3123.staffchat.util.StringUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
|
@ -45,8 +46,8 @@ public class ChatListener implements Listener
|
|||
}
|
||||
format = chatEvent.getFormat();
|
||||
|
||||
format = format.replaceAll("\\{NAME\\}", sanitize(event.getPlayer().getName()));
|
||||
format = format.replaceAll("\\{MESSAGE\\}", sanitize(message));
|
||||
format = format.replaceAll("\\{NAME\\}", StringUtils.sanitize(event.getPlayer().getName()));
|
||||
format = format.replaceAll("\\{MESSAGE\\}", StringUtils.sanitize(message));
|
||||
format = ChatColor.translateAlternateColorCodes('&', format);
|
||||
final String finalMessage = format;
|
||||
|
||||
|
@ -58,11 +59,4 @@ public class ChatListener implements Listener
|
|||
event.setCancelled(true);
|
||||
}
|
||||
|
||||
private String sanitize(String string)
|
||||
{
|
||||
string = string.replaceAll("\\\\", "\\\\\\\\");
|
||||
string = string.replaceAll("\\$", "\\\\\\$");
|
||||
return string;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,13 @@
|
|||
package me.oskar3123.staffchat.util;
|
||||
|
||||
public class StringUtils
|
||||
{
|
||||
|
||||
public static String sanitize(String string)
|
||||
{
|
||||
string = string.replaceAll("\\\\", "\\\\\\\\");
|
||||
string = string.replaceAll("\\$", "\\\\\\$");
|
||||
return string;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,15 @@
|
|||
package me.oskar3123.staffchat.util;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
public class StringUtilsTest
|
||||
{
|
||||
|
||||
@Test
|
||||
public void sanitize()
|
||||
{
|
||||
assertEquals("message", "hejsan \\$ \\\\ xd", StringUtils.sanitize("hejsan $ \\ xd"));
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue