Skip to content

Commit

Permalink
Merge pull request #66 from jenkinsci/JENKINS-45221
Browse files Browse the repository at this point in the history
[JENKINS-45221] Use case insensitive path when computing the workspace relative path
  • Loading branch information
Cyrille Le Clerc committed Jul 19, 2017
2 parents 7a519b1 + 6eeb98c commit 3dfcb67
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
Expand Up @@ -222,11 +222,11 @@ public static String getPathInWorkspace(@Nonnull final String absoluteFilePath,
sanitizedWorkspaceRemote = workspaceRemote;
}

if (!sanitizedAbsoluteFilePath.startsWith(sanitizedWorkspaceRemote)) {
if (!StringUtils.startsWithIgnoreCase(sanitizedAbsoluteFilePath, sanitizedWorkspaceRemote)) {
throw new IllegalArgumentException("Cannot relativize '" + absoluteFilePath + "' relatively to '" + workspace.getRemote() + "'");
}

String relativePath = StringUtils.substringAfter(sanitizedAbsoluteFilePath, sanitizedWorkspaceRemote);
String relativePath = StringUtils.removeStartIgnoreCase(sanitizedAbsoluteFilePath, sanitizedWorkspaceRemote);
String fileSeparator = windows ? "\\" : "/";

if (relativePath.startsWith(fileSeparator)) {
Expand Down
Expand Up @@ -5,6 +5,7 @@
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.jvnet.hudson.test.Issue;
import org.w3c.dom.Element;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
Expand Down Expand Up @@ -177,6 +178,17 @@ public void test_getPathInWorkspace_windows_with_mixed_separators_ok(){
Assert.assertThat(actual, CoreMatchers.is(expected));
}

@Issue("JENKINS-45221")
@Test
public void test_getPathInWorkspace_windows_mixed_case_ok_JENKINS_45221() {
// lowercase versus uppercase "d:\"
String workspace = "d:\\jenkins\\workspace\\d.admin_feature_Jenkinsfile-SCSMHLROYAGBAWY5ZNNG6ALR77MVLEH3F3EFF3O7XN3RO5BL6AMA";
String absolutePath = "D:\\jenkins\\workspace\\d.admin_feature_Jenkinsfile-SCSMHLROYAGBAWY5ZNNG6ALR77MVLEH3F3EFF3O7XN3RO5BL6AMA\\admin\\xyz\\target\\pad-admin-xyz-2.4.0-SNAPSHOT-tests.jar";
String actual = XmlUtils.getPathInWorkspace(absolutePath, new FilePath(new File(workspace)));
String expected = "admin\\xyz\\target\\pad-admin-xyz-2.4.0-SNAPSHOT-tests.jar";
Assert.assertThat(actual, CoreMatchers.is(expected));
}

@Test(expected = IllegalArgumentException.class)
public void test_getPathInWorkspace_windows_ko(){
String workspace = "C:\\path\\to\\spring-petclinic";
Expand Down
Expand Up @@ -3,7 +3,7 @@
#

# cf. JavaContainer/Dockerfile
FROM jenkins/java:42a1c8d4b931
FROM jenkins/java:eed7706a10fb

RUN apt-get update
RUN apt-get install --no-install-recommends -y git

0 comments on commit 3dfcb67

Please sign in to comment.