summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKHobbits <rob@khobbits.co.uk>2012-02-02 09:26:36 +0000
committerKHobbits <rob@khobbits.co.uk>2012-02-02 09:26:36 +0000
commit5c19e71858ad3e4605156bead2e29fdccb512ed0 (patch)
tree4c807a6e5fcc5834edc6c7a8319d32137f35f681
parent92fa415848453fc3e0ca0471729363b358930e18 (diff)
downloadEssentials-5c19e71858ad3e4605156bead2e29fdccb512ed0.tar
Essentials-5c19e71858ad3e4605156bead2e29fdccb512ed0.tar.gz
Essentials-5c19e71858ad3e4605156bead2e29fdccb512ed0.tar.lz
Essentials-5c19e71858ad3e4605156bead2e29fdccb512ed0.tar.xz
Essentials-5c19e71858ad3e4605156bead2e29fdccb512ed0.zip
Sanitize mail for untoward characters.
Prevent a user error from terminating essentials timer task.
-rw-r--r--Essentials/src/com/earth2me/essentials/EssentialsTimer.java16
-rw-r--r--Essentials/src/com/earth2me/essentials/Util.java10
-rw-r--r--Essentials/src/com/earth2me/essentials/commands/Commandmail.java7
-rw-r--r--Essentials/src/com/earth2me/essentials/signs/SignProtection.java2
4 files changed, 25 insertions, 10 deletions
diff --git a/Essentials/src/com/earth2me/essentials/EssentialsTimer.java b/Essentials/src/com/earth2me/essentials/EssentialsTimer.java
index f3b447dae..0c413bfc8 100644
--- a/Essentials/src/com/earth2me/essentials/EssentialsTimer.java
+++ b/Essentials/src/com/earth2me/essentials/EssentialsTimer.java
@@ -3,6 +3,7 @@ package com.earth2me.essentials;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;
+import java.util.logging.Level;
import org.bukkit.entity.Player;
@@ -22,10 +23,17 @@ public class EssentialsTimer implements Runnable
final long currentTime = System.currentTimeMillis();
for (Player player : ess.getServer().getOnlinePlayers())
{
- final User user = ess.getUser(player);
- onlineUsers.add(user);
- user.setLastOnlineActivity(currentTime);
- user.checkActivity();
+ try
+ {
+ final User user = ess.getUser(player);
+ onlineUsers.add(user);
+ user.setLastOnlineActivity(currentTime);
+ user.checkActivity();
+ }
+ catch (Exception e)
+ {
+ ess.getLogger().log(Level.WARNING, "EssentialsTimer Error:", e);
+ }
}
final Iterator<User> iterator = onlineUsers.iterator();
diff --git a/Essentials/src/com/earth2me/essentials/Util.java b/Essentials/src/com/earth2me/essentials/Util.java
index 386433326..48e2a53a0 100644
--- a/Essentials/src/com/earth2me/essentials/Util.java
+++ b/Essentials/src/com/earth2me/essentials/Util.java
@@ -21,11 +21,17 @@ public class Util
{
}
private final static Logger logger = Logger.getLogger("Minecraft");
- private final static Pattern INVALIDCHARS = Pattern.compile("[^a-z0-9]");
+ private final static Pattern INVALIDFILECHARS = Pattern.compile("[^a-z0-9]");
+ private final static Pattern INVALIDCHARS = Pattern.compile("[^\\p{Print}]");
public static String sanitizeFileName(final String name)
{
- return INVALIDCHARS.matcher(name.toLowerCase(Locale.ENGLISH)).replaceAll("_");
+ return INVALIDFILECHARS.matcher(name.toLowerCase(Locale.ENGLISH)).replaceAll("_");
+ }
+
+ public static String sanitizeString(final String string)
+ {
+ return INVALIDCHARS.matcher(string).replaceAll("");
}
public static String formatDateDiff(long date)
diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandmail.java b/Essentials/src/com/earth2me/essentials/commands/Commandmail.java
index 4a9928b85..abc551f58 100644
--- a/Essentials/src/com/earth2me/essentials/commands/Commandmail.java
+++ b/Essentials/src/com/earth2me/essentials/commands/Commandmail.java
@@ -40,7 +40,7 @@ public class Commandmail extends EssentialsCommand
{
if (!user.isAuthorized("essentials.mail.send"))
{
- throw new Exception(_("noPerm","essentials.mail.send"));
+ throw new Exception(_("noPerm", "essentials.mail.send"));
}
Player player = server.getPlayer(args[1]);
@@ -59,7 +59,8 @@ public class Commandmail extends EssentialsCommand
}
if (!u.isIgnoredPlayer(user.getName()))
{
- u.addMail(user.getName() + ": " + Util.stripColor(getFinalArg(args, 2)));
+ final String mail = Util.sanitizeString(Util.stripColor(getFinalArg(args, 2)));
+ u.addMail(user.getName() + ": " + mail);
}
user.sendMessage(_("mailSent"));
return;
@@ -68,7 +69,7 @@ public class Commandmail extends EssentialsCommand
{
if (!user.isAuthorized("essentials.mail.sendall"))
{
- throw new Exception(_("noPerm","essentials.mail.sendall"));
+ throw new Exception(_("noPerm", "essentials.mail.sendall"));
}
ess.scheduleAsyncDelayedTask(new SendAll(user.getName() + ": " + Util.stripColor(getFinalArg(args, 1))));
user.sendMessage(_("mailSent"));
diff --git a/Essentials/src/com/earth2me/essentials/signs/SignProtection.java b/Essentials/src/com/earth2me/essentials/signs/SignProtection.java
index f64b6f3f1..088e74f01 100644
--- a/Essentials/src/com/earth2me/essentials/signs/SignProtection.java
+++ b/Essentials/src/com/earth2me/essentials/signs/SignProtection.java
@@ -129,7 +129,7 @@ public class SignProtection extends EssentialsSign
if (block.getType() == Material.SIGN_POST || block.getType() == Material.WALL_SIGN)
{
final BlockSign sign = new BlockSign(block);
- if (sign.getLine(0).equalsIgnoreCase(this.getSuccessName()))
+ if (sign.getLine(0).equals(this.getSuccessName()))
{
return checkProtectionSign(sign, user, username);
}