@@ -757,7 +757,7 @@ public static int indexOfExtension(final String filename) {
757757 * ie. both Unix and Windows prefixes are matched regardless.
758758 *
759759 * @param filename the filename to query, null returns null
760- * @return the prefix of the file, null if invalid
760+ * @return the prefix of the file, null if invalid. Null bytes inside string will be removed
761761 */
762762 public static String getPrefix (final String filename ) {
763763 if (filename == null ) {
@@ -768,9 +768,9 @@ public static String getPrefix(final String filename) {
768768 return null ;
769769 }
770770 if (len > filename .length ()) {
771- return filename + UNIX_SEPARATOR ; // we know this only happens for unix
771+ return filterNullBytes ( filename + UNIX_SEPARATOR ) ; // we know this only happens for unix
772772 }
773- return filename .substring (0 , len );
773+ return filterNullBytes ( filename .substring (0 , len ) );
774774 }
775775
776776 /**
@@ -793,7 +793,8 @@ public static String getPrefix(final String filename) {
793793 * See {@link #getFullPath(String)} for the method that retains the prefix.
794794 *
795795 * @param filename the filename to query, null returns null
796- * @return the path of the file, an empty string if none exists, null if invalid
796+ * @return the path of the file, an empty string if none exists, null if invalid.
797+ * Null bytes inside string will be removed
797798 */
798799 public static String getPath (final String filename ) {
799800 return doGetPath (filename , 1 );
@@ -820,7 +821,8 @@ public static String getPath(final String filename) {
820821 * See {@link #getFullPathNoEndSeparator(String)} for the method that retains the prefix.
821822 *
822823 * @param filename the filename to query, null returns null
823- * @return the path of the file, an empty string if none exists, null if invalid
824+ * @return the path of the file, an empty string if none exists, null if invalid.
825+ * Null bytes inside string will be removed
824826 */
825827 public static String getPathNoEndSeparator (final String filename ) {
826828 return doGetPath (filename , 0 );
@@ -831,7 +833,7 @@ public static String getPathNoEndSeparator(final String filename) {
831833 *
832834 * @param filename the filename
833835 * @param separatorAdd 0 to omit the end separator, 1 to return it
834- * @return the path
836+ * @return the path. Null bytes inside string will be removed
835837 */
836838 private static String doGetPath (final String filename , final int separatorAdd ) {
837839 if (filename == null ) {
@@ -846,7 +848,7 @@ private static String doGetPath(final String filename, final int separatorAdd) {
846848 if (prefix >= filename .length () || index < 0 || prefix >= endIndex ) {
847849 return "" ;
848850 }
849- return filename .substring (prefix , endIndex );
851+ return filterNullBytes ( filename .substring (prefix , endIndex ) );
850852 }
851853
852854 /**
0 commit comments