Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ public void run(final Server server, final User user, final String commandLabel,
throw new TranslatableException("invalidWarpName");
}

if (StringUtil.isReservedFileName(args[0])) {
throw new TranslatableException("invalidWarpName");
}

final IWarps warps = ess.getWarps();
Location warpLoc = null;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,21 @@ public final class StringUtil {
private StringUtil() {
}

private static final Pattern WINDOWS_RESERVED = Pattern.compile("^(con|prn|aux|nul|com[0-9]|lpt[0-9])$");

//Used to clean file names before saving to disk
public static String sanitizeFileName(final String name) {
return INVALIDFILECHARS.matcher(name.toLowerCase(Locale.ENGLISH)).replaceAll("_");
}

/**
* Returns true if the given name is a Windows reserved filename (e.g. CON, NUL, AUX).
* Using these as file names on Windows will hang or crash the server.
*/
public static boolean isReservedFileName(final String name) {
return WINDOWS_RESERVED.matcher(name.toLowerCase(Locale.ENGLISH)).matches();
}

//Used to clean strings/names before saving as filenames/permissions
public static String safeString(final String string) {
if (string == null) {
Expand Down
Loading