get/stripFilenameExtension correctly ignores Unix-style hidden directories (SPR-7828)
This commit is contained in:
@@ -529,8 +529,15 @@ public abstract class StringUtils {
|
||||
if (path == null) {
|
||||
return null;
|
||||
}
|
||||
int sepIndex = path.lastIndexOf(EXTENSION_SEPARATOR);
|
||||
return (sepIndex != -1 ? path.substring(sepIndex + 1) : null);
|
||||
int extIndex = path.lastIndexOf(EXTENSION_SEPARATOR);
|
||||
if (extIndex == -1) {
|
||||
return null;
|
||||
}
|
||||
int folderIndex = path.lastIndexOf(FOLDER_SEPARATOR);
|
||||
if (folderIndex > extIndex) {
|
||||
return null;
|
||||
}
|
||||
return path.substring(extIndex + 1);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -544,8 +551,15 @@ public abstract class StringUtils {
|
||||
if (path == null) {
|
||||
return null;
|
||||
}
|
||||
int sepIndex = path.lastIndexOf(EXTENSION_SEPARATOR);
|
||||
return (sepIndex != -1 ? path.substring(0, sepIndex) : path);
|
||||
int extIndex = path.lastIndexOf(EXTENSION_SEPARATOR);
|
||||
if (extIndex == -1) {
|
||||
return path;
|
||||
}
|
||||
int folderIndex = path.lastIndexOf(FOLDER_SEPARATOR);
|
||||
if (folderIndex > extIndex) {
|
||||
return path;
|
||||
}
|
||||
return path.substring(0, extIndex);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -653,7 +667,7 @@ public abstract class StringUtils {
|
||||
public static Locale parseLocaleString(String localeString) {
|
||||
for (int i = 0; i < localeString.length(); i++) {
|
||||
char ch = localeString.charAt(i);
|
||||
if (ch != '_' && !Character.isLetterOrDigit(ch)) {
|
||||
if (ch != '_' && ch != ' ' && !Character.isLetterOrDigit(ch)) {
|
||||
throw new IllegalArgumentException(
|
||||
"Locale value \"" + localeString + "\" contains invalid characters");
|
||||
}
|
||||
|
||||
@@ -268,7 +268,7 @@ public class StringUtilsTests extends TestCase {
|
||||
assertEquals(null, StringUtils.getFilenameExtension(""));
|
||||
assertEquals(null, StringUtils.getFilenameExtension("myfile"));
|
||||
assertEquals(null, StringUtils.getFilenameExtension("myPath/myfile"));
|
||||
assertEquals(null, StringUtils.getFilenameExtension("/home/user/.m2/settings"));
|
||||
assertEquals(null, StringUtils.getFilenameExtension("/home/user/.m2/settings/myfile"));
|
||||
assertEquals("", StringUtils.getFilenameExtension("myfile."));
|
||||
assertEquals("", StringUtils.getFilenameExtension("myPath/myfile."));
|
||||
assertEquals("txt", StringUtils.getFilenameExtension("myfile.txt"));
|
||||
@@ -285,9 +285,9 @@ public class StringUtilsTests extends TestCase {
|
||||
assertEquals("mypath/myfile", StringUtils.stripFilenameExtension("mypath/myfile"));
|
||||
assertEquals("mypath/myfile", StringUtils.stripFilenameExtension("mypath/myfile."));
|
||||
assertEquals("mypath/myfile", StringUtils.stripFilenameExtension("mypath/myfile.txt"));
|
||||
assertEquals("/home/user/.m2/settings", StringUtils.stripFilenameExtension("/home/user/.m2/settings"));
|
||||
assertEquals("/home/user/.m2/settings", StringUtils.stripFilenameExtension("/home/user/.m2/settings/myfile."));
|
||||
assertEquals("/home/user/.m2/settings", StringUtils.stripFilenameExtension("/home/user/.m2/settings/myfile.txt"));
|
||||
assertEquals("/home/user/.m2/settings/myfile", StringUtils.stripFilenameExtension("/home/user/.m2/settings/myfile"));
|
||||
assertEquals("/home/user/.m2/settings/myfile", StringUtils.stripFilenameExtension("/home/user/.m2/settings/myfile."));
|
||||
assertEquals("/home/user/.m2/settings/myfile", StringUtils.stripFilenameExtension("/home/user/.m2/settings/myfile.txt"));
|
||||
}
|
||||
|
||||
public void testCleanPath() {
|
||||
|
||||
Reference in New Issue
Block a user