Skip to content
Permalink
Browse files
Null-guard and fix lower case. Fix typo.
  • Loading branch information
garydgregory committed Feb 20, 2022
1 parent c936bba commit cefdd552695462b81c3a57f072bd1ceda263e34b
Showing 1 changed file with 19 additions and 20 deletions.
@@ -1699,32 +1699,31 @@ private long parseOctalOrBinary(final byte[] header, final int offset, final int
}

/**
* Strips Windows' drive letter as well as any leading slashes,
* turns path separators into forward slahes.
* Strips Windows' drive letter as well as any leading slashes, turns path separators into forward slashes.
*/
private static String normalizeFileName(String fileName,
final boolean preserveAbsolutePath) {
private static String normalizeFileName(String fileName, final boolean preserveAbsolutePath) {
if (!preserveAbsolutePath) {
final String osname = System.getProperty("os.name").toLowerCase(Locale.ENGLISH);
final String property = System.getProperty("os.name");
if (property != null) {
final String osName = property.toLowerCase(Locale.ROOT);

// Strip off drive letters!
// REVIEW Would a better check be "(File.separator == '\')"?
// Strip off drive letters!
// REVIEW Would a better check be "(File.separator == '\')"?

if (osname.startsWith("windows")) {
if (fileName.length() > 2) {
final char ch1 = fileName.charAt(0);
final char ch2 = fileName.charAt(1);
if (osName.startsWith("windows")) {
if (fileName.length() > 2) {
final char ch1 = fileName.charAt(0);
final char ch2 = fileName.charAt(1);

if (ch2 == ':'
&& (ch1 >= 'a' && ch1 <= 'z'
|| ch1 >= 'A' && ch1 <= 'Z')) {
fileName = fileName.substring(2);
if (ch2 == ':' && (ch1 >= 'a' && ch1 <= 'z' || ch1 >= 'A' && ch1 <= 'Z')) {
fileName = fileName.substring(2);
}
}
} else if (osName.contains("netware")) {
final int colon = fileName.indexOf(':');
if (colon != -1) {
fileName = fileName.substring(colon + 1);
}
}
} else if (osname.contains("netware")) {
final int colon = fileName.indexOf(':');
if (colon != -1) {
fileName = fileName.substring(colon + 1);
}
}
}

0 comments on commit cefdd55

Please sign in to comment.