get/stripFilenameExtension correctly ignores Unix-style hidden directories (SPR-7828)

This commit is contained in:
Juergen Hoeller
2011-01-26 20:47:45 +00:00
parent 7af890cc5f
commit 9dd6f467b9
2 changed files with 23 additions and 9 deletions

View File

@@ -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");
}