Skip to content

Commit

Permalink
Merge pull request #479 from stefanhahmann/file-list-coverters-empty-…
Browse files Browse the repository at this point in the history
…input

Ignore empty Strings during String to FileArray conversion
  • Loading branch information
ctrueden committed Jul 10, 2024
2 parents 37abc7e + 8dc4c0e commit a2d0042
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/main/java/org/scijava/convert/FileListConverters.java
Original file line number Diff line number Diff line change
Expand Up @@ -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()]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit a2d0042

Please sign in to comment.