From a1a5e1190d092b681017d4824dcdae93fcc008bf Mon Sep 17 00:00:00 2001 From: md_5 Date: Sat, 7 Jul 2018 09:21:17 +1000 Subject: SPIGOT-3988: Error on manually constructed PluginDescriptionFile --- src/main/java/org/bukkit/plugin/PluginDescriptionFile.java | 11 +++++++++-- 1 file 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; * */ public final class PluginDescriptionFile { + private static final Pattern VALID_NAME = Pattern.compile("^[A-Za-z0-9 _.-]+$"); private static final ThreadLocal YAML = new ThreadLocal() { @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(' ', '_'); -- cgit v1.2.3