Skip to content
Permalink
Browse files

[FIXED JENKINS-18970] Escape File.separator when used in a regex.

  • Loading branch information
aitorthered authored and orrc committed Aug 3, 2013
1 parent eaa2afe commit 378acf0718d7c3086dbbbac6cfb1f0fe5ca9022e
Showing with 5 additions and 3 deletions.
  1. +5 −3 src/main/java/hudson/plugins/android_emulator/util/Utils.java
@@ -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

0 comments on commit 378acf0

Please sign in to comment.
You can’t perform that action at this time.