From 2f279a6ab6af75d6cbace7a7882878b3b6f6eeb1 Mon Sep 17 00:00:00 2001 From: stijnb1234 Date: Mon, 20 Jun 2022 22:10:30 +0200 Subject: [PATCH] Updated dependencies (1.19 ready) --- pom.xml | 23 ++++------- .../sbdeveloper/mctpaudio/utils/HeadUtil.java | 39 ++++++++++++++++++- 2 files changed, 44 insertions(+), 18 deletions(-) diff --git a/pom.xml b/pom.xml index fa1ef2a..d391126 100644 --- a/pom.xml +++ b/pom.xml @@ -97,19 +97,20 @@ org.spigotmc spigot-api - 1.18.2-R0.1-SNAPSHOT + 1.19-R0.1-SNAPSHOT provided + org.bukkit craftbukkit - 1.18.2-R0.1-SNAPSHOT + 1.19-R0.1-SNAPSHOT provided org.java-websocket Java-WebSocket - 1.5.2 + 1.5.3 com.mpatric @@ -119,7 +120,7 @@ com.sk89q.worldguard worldguard-bukkit - 7.0.7-SNAPSHOT + 7.1.0-SNAPSHOT provided @@ -128,16 +129,6 @@ 1.18.1 provided - - - - - - - - - - co.aikar acf-paper @@ -147,13 +138,13 @@ com.bergerkiller.bukkit BKCommonLib - 1.18.2-v1 + 1.19-v1 provided com.bergerkiller.bukkit TrainCarts - 1.18.2-v1 + 1.19-v1 provided diff --git a/src/main/java/nl/sbdeveloper/mctpaudio/utils/HeadUtil.java b/src/main/java/nl/sbdeveloper/mctpaudio/utils/HeadUtil.java index e9d8638..405196f 100644 --- a/src/main/java/nl/sbdeveloper/mctpaudio/utils/HeadUtil.java +++ b/src/main/java/nl/sbdeveloper/mctpaudio/utils/HeadUtil.java @@ -3,7 +3,6 @@ package nl.sbdeveloper.mctpaudio.utils; import com.mpatric.mp3agic.InvalidDataException; import com.mpatric.mp3agic.Mp3File; import com.mpatric.mp3agic.UnsupportedTagException; -import org.apache.commons.io.FilenameUtils; import java.io.File; import java.io.FileOutputStream; @@ -78,7 +77,7 @@ public class HeadUtil { public static int getTicksOfFile(String input) throws IOException, InvalidDataException, UnsupportedTagException { URL url = new URL(input); - String result = downloadFromUrl(url, FilenameUtils.getName(url.getPath())); + String result = downloadFromUrl(url, getName(url.getPath())); File file = new File(result); if (!file.exists()) return 0; @@ -90,4 +89,40 @@ public class HeadUtil { return (int) (sec * 20); } + + private static final int NOT_FOUND = -1; + + /** + * The Unix separator character. + */ + private static final char UNIX_NAME_SEPARATOR = '/'; + + /** + * The Windows separator character. + */ + private static final char WINDOWS_NAME_SEPARATOR = '\\'; + + private static String getName(final String fileName) { + if (fileName == null) { + return null; + } + return requireNonNullChars(fileName).substring(indexOfLastSeparator(fileName) + 1); + } + + private static String requireNonNullChars(final String path) { + if (path.indexOf(0) >= 0) { + throw new IllegalArgumentException( + "Null character present in file/path name. There are no known legitimate use cases for such data, but several injection attacks may use it"); + } + return path; + } + + private static int indexOfLastSeparator(final String fileName) { + if (fileName == null) { + return NOT_FOUND; + } + final int lastUnixPos = fileName.lastIndexOf(UNIX_NAME_SEPARATOR); + final int lastWindowsPos = fileName.lastIndexOf(WINDOWS_NAME_SEPARATOR); + return Math.max(lastUnixPos, lastWindowsPos); + } }