Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrap classpath entries which contains spaces in quotation marks #803

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 11 additions & 13 deletions src/fitnesse/testsystems/ClassPath.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,34 +22,32 @@ public ClassPath(String defaultPath, String pathSeparator) {

public ClassPath(List<ClassPath> paths) {
this.elements = new ArrayList<String>();
this.separator = paths.get(0).getSeparator();
this.separator = paths.get(0).separator;

for (ClassPath path : paths) {
for (String element : path.getElements()) {
for (String element : path.elements) {
if (!elements.contains(element)) {
elements.add(element);
}
}
}
}

public List<String> getElements() {
return elements;
}

public String getSeparator() {
return separator;
}

@Override
public String toString() {
if (elements.isEmpty()) {
return "defaultPath";
} else {
String result = StringUtils.join(elements, separator);
if (result.contains(" ") && !(result.startsWith("\"") && result.endsWith("\""))) {
result = "\""+result +"\"";
List<String> newElements = new ArrayList<String>();
for (String element : elements) {
if (element.contains(" ") && !(element.startsWith("\"") && element.endsWith("\""))) {
newElements.add("\""+element +"\"");
} else {
newElements.add(element);
}
}

String result = StringUtils.join(newElements, separator);
return result;
}
}
Expand Down
6 changes: 6 additions & 0 deletions test/fitnesse/testsystems/ClassPathTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,10 @@ public void shouldMergeClassPaths() {

assertThat(cp.toString(), is("foo.jar,baz.jar,bar.jar"));
}

@Test
public void shouldHandleSpaceInPath() {
ClassPath cp = new ClassPath(asList("dir/foo.jar", "other dir/bar.jar"), ";");
assertThat(cp.toString(), is("dir/foo.jar;\"other dir/bar.jar\""));
}
}