refactor: remove out-of-bounds location in LocationArgumentType since it's pointless

This commit is contained in:
Chayapak Supasakul 2025-03-03 15:21:07 +07:00
parent 7f9d942754
commit 3a5e4490ee
Signed by: ChomeNS
SSH key fingerprint: SHA256:0YoxhdyXsgbc0nfeB2N6FYE60mxMU7DS4uCUMaw2mvA

View file

@ -18,8 +18,6 @@ import java.util.Collection;
public class LocationArgumentType implements ArgumentType<Object> { public class LocationArgumentType implements ArgumentType<Object> {
private static final Collection<String> EXAMPLES = Arrays.asList("songs/amogus.mid", "images/cat.jpg", "videos/badapple.mp4"); private static final Collection<String> EXAMPLES = Arrays.asList("songs/amogus.mid", "images/cat.jpg", "videos/badapple.mp4");
private static final SimpleCommandExceptionType OOB_FILEPATH = new SimpleCommandExceptionType(Text.translatable("The specified file path is outside of the allowed directory"));
private final boolean allowsUrls; private final boolean allowsUrls;
private final boolean allowsPaths; private final boolean allowsPaths;
private final Path root; private final Path root;
@ -59,9 +57,7 @@ public class LocationArgumentType implements ArgumentType<Object> {
public Path parsePath (StringReader reader) throws CommandSyntaxException { public Path parsePath (StringReader reader) throws CommandSyntaxException {
final String pathString = reader.readString(); final String pathString = reader.readString();
final Path path = Path.of(root.toString(), pathString).toAbsolutePath().normalize(); return Path.of(root.toString(), pathString).toAbsolutePath().normalize();
if (!path.startsWith(root)) throw OOB_FILEPATH.create();
return path;
} }
private static Object getLocation (CommandContext<?> context, String name) { private static Object getLocation (CommandContext<?> context, String name) {