SPIGOT-3988: Error on manually constructed PluginDescriptionFile

By: md_5 <git@md-5.net>
This commit is contained in:
Bukkit/Spigot
2018-07-07 09:21:17 +10:00
parent f63661d5f6
commit 0bea165ff0

View File

@@ -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(' ', '_');