Skip to content

Commit

Permalink
[FIXED JENKINS-18970] Escape File.separator when used in a regex.
Browse files Browse the repository at this point in the history
  • Loading branch information
aitorthered authored and orrc committed Aug 3, 2013
1 parent eaa2afe commit 378acf0
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/main/java/hudson/plugins/android_emulator/util/Utils.java
Expand Up @@ -604,18 +604,20 @@ public static String getRelativePath(String from, String to) {
if (fromPath.equals(toPath)) {
return "";
}

// Target directory is a subdirectory
if (toPath.startsWith(fromPath)) {
int fromLength = fromPath.length();
int index = fromLength == 1 ? 1 : fromLength + 1;
return toPath.substring(index) + File.separatorChar;
}

// Quote separator, as String.split() takes a regex and
// File.separator isn't a valid regex character on Windows
final String separator = Pattern.quote(File.separator);
// Target directory is somewhere above our directory
String[] fromParts = fromPath.substring(1).split(File.separator);
String[] fromParts = fromPath.substring(1).split(separator);
final int fromLength = fromParts.length;
String[] toParts = toPath.substring(1).split(File.separator);
String[] toParts = toPath.substring(1).split(separator);
final int toLength = toParts.length;

// Find the number of common path segments
Expand Down

0 comments on commit 378acf0

Please sign in to comment.