summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormd_5 <git@md-5.net>2018-07-07 09:21:17 +1000
committermd_5 <git@md-5.net>2018-07-07 09:21:17 +1000
commita1a5e1190d092b681017d4824dcdae93fcc008bf (patch)
tree8face34cba57878fba7e9a70963f4c80f6aa62b4
parent59b49b81dd4dd7c29debd3bb46961001531ea5ca (diff)
downloadbukkit-a1a5e1190d092b681017d4824dcdae93fcc008bf.tar
bukkit-a1a5e1190d092b681017d4824dcdae93fcc008bf.tar.gz
bukkit-a1a5e1190d092b681017d4824dcdae93fcc008bf.tar.lz
bukkit-a1a5e1190d092b681017d4824dcdae93fcc008bf.tar.xz
bukkit-a1a5e1190d092b681017d4824dcdae93fcc008bf.zip
SPIGOT-3988: Error on manually constructed PluginDescriptionFile
-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(' ', '_');