13
0
geforkt von Mirrors/Paper

SPIGOT-3988: Error on manually constructed PluginDescriptionFile

By: md_5 <git@md-5.net>
Dieser Commit ist enthalten in:
Bukkit/Spigot 2018-07-07 09:21:17 +10:00
Ursprung f63661d5f6
Commit 0bea165ff0

Datei anzeigen

@ -8,6 +8,7 @@ import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import java.util.regex.Pattern;
import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandExecutor;
import org.bukkit.command.PluginCommand; import org.bukkit.command.PluginCommand;
@ -170,6 +171,7 @@ import com.google.common.collect.ImmutableSet;
*</pre></blockquote> *</pre></blockquote>
*/ */
public final class PluginDescriptionFile { 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>() { private static final ThreadLocal<Yaml> YAML = new ThreadLocal<Yaml>() {
@Override @Override
protected Yaml initialValue() { protected Yaml initialValue() {
@ -245,7 +247,12 @@ public final class PluginDescriptionFile {
* @param mainClass Full location of the main class of this plugin * @param mainClass Full location of the main class of this plugin
*/ */
public PluginDescriptionFile(final String pluginName, final String pluginVersion, final String mainClass) { 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; version = pluginVersion;
main = mainClass; main = mainClass;
} }
@ -861,7 +868,7 @@ public final class PluginDescriptionFile {
try { try {
name = rawName = map.get("name").toString(); 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."); throw new InvalidDescriptionException("name '" + name + "' contains invalid characters.");
} }
name = name.replace(' ', '_'); name = name.replace(' ', '_');