summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/main/java/org/bukkit/plugin/PluginDescriptionFile.java11
1 files changed, 9 insertions, 2 deletions
diff --git a/src/main/java/org/bukkit/plugin/PluginDescriptionFile.java b/src/main/java/org/bukkit/plugin/PluginDescriptionFile.java
index 4cdaac45..27a64828 100644
--- a/src/main/java/org/bukkit/plugin/PluginDescriptionFile.java
+++ b/src/main/java/org/bukkit/plugin/PluginDescriptionFile.java
@@ -8,6 +8,7 @@ import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
+import java.util.regex.Pattern;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.PluginCommand;
@@ -170,6 +171,7 @@ import com.google.common.collect.ImmutableSet;
*</pre></blockquote>
*/
public final class PluginDescriptionFile {
+ private static final Pattern VALID_NAME = Pattern.compile("^[A-Za-z0-9 _.-]+$");
private static final ThreadLocal<Yaml> YAML = new ThreadLocal<Yaml>() {
@Override
protected Yaml initialValue() {
@@ -245,7 +247,12 @@ public final class PluginDescriptionFile {
* @param mainClass Full location of the main class of this plugin
*/
public PluginDescriptionFile(final String pluginName, final String pluginVersion, final String mainClass) {
- name = pluginName.replace(' ', '_');
+ name = rawName = pluginName;
+
+ if (!VALID_NAME.matcher(name).matches()) {
+ throw new IllegalArgumentException("name '" + name + "' contains invalid characters.");
+ }
+ name = name.replace(' ', '_');
version = pluginVersion;
main = mainClass;
}
@@ -861,7 +868,7 @@ public final class PluginDescriptionFile {
try {
name = rawName = map.get("name").toString();
- if (!name.matches("^[A-Za-z0-9 _.-]+$")) {
+ if (!VALID_NAME.matcher(name).matches()) {
throw new InvalidDescriptionException("name '" + name + "' contains invalid characters.");
}
name = name.replace(' ', '_');