Skip to content

Ignore empty Strings during String to FileArray conversion #479

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

Merged
Merged
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
2 changes: 2 additions & 0 deletions src/main/java/org/scijava/convert/FileListConverters.java
Original file line number Diff line number Diff line change
@@ -82,6 +82,8 @@ public <T> T convert(final Object src, final Class<T> dest) {
final String[] tokens = StringUtils.splitUnquoted((String) src, ",");
final List<File> fileList = new ArrayList<>();
for (final String filePath : tokens) {
if ( filePath.isEmpty() )
continue;
fileList.add(new File(filePath.replaceAll("^\"|\"$", "")));
}
return (T) fileList.toArray(new File[fileList.size()]);
Original file line number Diff line number Diff line change
@@ -69,6 +69,7 @@ public void testStringToFileArrayConverter() {
conv.convert(path, File[].class)[0]);
assertEquals("Wrong file name", new File("C:\\temp"),
conv.convert(path, File[].class)[1]);
assertEquals( 0, conv.convert( "", File[].class ).length );
}

@Test