Skip to content

Commit

Permalink
fixed problem with special characters in job, folder and view names
Browse files Browse the repository at this point in the history
[FIXES JENKINS-44140]
  • Loading branch information
daspilker committed May 9, 2017
1 parent a36bd45 commit 436b546
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 14 deletions.
2 changes: 2 additions & 0 deletions docs/Home.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ Browse the Jenkins issue tracker to see any [open issues](https://issues.jenkins

## Release Notes
* 1.63 (unreleased)
* Fixed problem with special characters in job, folder and view names
([JENKINS-44140](https://issues.jenkins-ci.org/browse/JENKINS-44140))
* 1.62 (May 09 2017)
* Show enum values for generated DSL in embedded API viewer
[#1020](https://github.com/jenkinsci/job-dsl-plugin/pull/1020)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
import hudson.model.Item;
import hudson.model.ItemGroup;
import jenkins.model.Jenkins;

import java.net.URI;
import org.apache.commons.io.FilenameUtils;

/**
* A JobLookupStrategy encapsulates where a seed job will look for existing jobs
Expand Down Expand Up @@ -48,7 +47,11 @@ protected ItemGroup getContext(Item seedJob) {
*/
public <T extends Item> T getItem(Item seedJob, String path, Class<T> type) {
String fullName = path.startsWith("/") ? path : getContext(seedJob).getFullName() + "/" + path;
return Jenkins.getInstance().getItemByFullName(normalizePath(fullName), type);
String normalizePath = normalizePath(fullName);
if (normalizePath == null) {
return null;
}
return Jenkins.getInstance().getItemByFullName(normalizePath, type);
}

/**
Expand Down Expand Up @@ -94,6 +97,9 @@ public String getDisplayName() {
private static ItemGroup getItemGroup(String path) {
Jenkins instance = Jenkins.getInstance();
String normalizedPath = normalizePath(path);
if (normalizedPath == null) {
return null;
}
if (normalizedPath.isEmpty() || normalizedPath.equals("/")) {
return instance;
}
Expand All @@ -102,6 +108,6 @@ private static ItemGroup getItemGroup(String path) {
}

private static String normalizePath(String path) {
return URI.create(path).normalize().getPath();
return FilenameUtils.normalize(path, true);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -106,20 +106,23 @@ class LookupStrategySpec extends Specification {
SEED_JOB | '/folder/foo' | 'folder'
}

def 'getParent not normalized'(LookupStrategy lookupStrategy, String path, String expectedFullName) {
@Unroll
def 'getParent not normalized for path #path and #strategy'(LookupStrategy strategy, String path, String expected) {
when:
ItemGroup result = lookupStrategy.getParent(seedJob, path)
ItemGroup result = strategy.getParent(seedJob, path)

then:
result?.fullName == expectedFullName
result?.fullName == expected

where:
lookupStrategy | path | expectedFullName
JENKINS_ROOT | '../folder/job' | null
SEED_JOB | '../folder/job' | 'folder'
JENKINS_ROOT | '/folder/../job' | ''
SEED_JOB | '/folder/../job' | ''
JENKINS_ROOT | 'folder/../job' | ''
SEED_JOB | 'folder/../job' | 'folder'
strategy | path | expected
JENKINS_ROOT | '../folder/job' | null
SEED_JOB | '../folder/job' | 'folder'
JENKINS_ROOT | '/folder/../job' | ''
SEED_JOB | '/folder/../job' | ''
JENKINS_ROOT | 'folder/../job' | ''
SEED_JOB | 'folder/../job' | 'folder'
JENKINS_ROOT | 'folder/with space/../../job' | ''
SEED_JOB | 'folder/with space/../../job' | 'folder'
}
}

0 comments on commit 436b546

Please sign in to comment.