From 5f0d48483227ef29e2d5403030d8f15d61226300 Mon Sep 17 00:00:00 2001 From: Louis Bergelson Date: Fri, 13 Oct 2023 18:02:59 -0400 Subject: [PATCH] Fix IOUtil.unrollPaths for http paths with query parameters (#1688) * Stop treating query parameters in an http path as part of the file extension --- src/main/java/htsjdk/samtools/util/IOUtil.java | 2 +- src/test/java/htsjdk/samtools/util/IOUtilTest.java | 10 +++++++++- .../htsjdk/samtools/io/FofnWithHttpQueryParams.fofn | 3 +++ 3 files changed, 13 insertions(+), 2 deletions(-) create mode 100644 src/test/resources/htsjdk/samtools/io/FofnWithHttpQueryParams.fofn diff --git a/src/main/java/htsjdk/samtools/util/IOUtil.java b/src/main/java/htsjdk/samtools/util/IOUtil.java index ce3c96fcd5..730506b2eb 100644 --- a/src/main/java/htsjdk/samtools/util/IOUtil.java +++ b/src/main/java/htsjdk/samtools/util/IOUtil.java @@ -1182,7 +1182,7 @@ public static List unrollPaths(final Collection inputs, final String while (!stack.empty()) { final Path p = stack.pop(); - final String name = p.toString(); + final String name = p.getFileName().toString(); boolean matched = false; for (final String ext : extensions) { diff --git a/src/test/java/htsjdk/samtools/util/IOUtilTest.java b/src/test/java/htsjdk/samtools/util/IOUtilTest.java index b61db443f0..7515766d03 100644 --- a/src/test/java/htsjdk/samtools/util/IOUtilTest.java +++ b/src/test/java/htsjdk/samtools/util/IOUtilTest.java @@ -450,6 +450,7 @@ public void testAssertDirectoryIsWritableFile(final File file, final boolean wri static final String level1 = "Level1.fofn"; static final String level2 = "Level2.fofn"; + static final String fofnHttpQueryParams = "FofnWithHttpQueryParams.fofn"; @DataProvider public Object[][] fofnData() throws IOException { @@ -460,11 +461,18 @@ public Object[][] fofnData() throws IOException { Path fofnPath2 = inMemoryFileSystem.getPath(level2); Files.copy(TEST_DATA_DIR.resolve(level2), fofnPath2); + Path withHttpPath = inMemoryFileSystem.getPath(fofnHttpQueryParams); + Files.copy(TEST_DATA_DIR.resolve(fofnHttpQueryParams), withHttpPath); + return new Object[][]{ {TEST_DATA_DIR + "/" + level1, new String[]{".vcf", ".vcf.gz"}, 2}, {TEST_DATA_DIR + "/" + level2, new String[]{".vcf", ".vcf.gz"}, 4}, {fofnPath1.toUri().toString(), new String[]{".vcf", ".vcf.gz"}, 2}, - {fofnPath2.toUri().toString(), new String[]{".vcf", ".vcf.gz"}, 4} + {fofnPath2.toUri().toString(), new String[]{".vcf", ".vcf.gz"}, 4}, + //test http links with query parameters are handled correctly + //test disabled until NIO http provider is integrated + //see https://github.com/samtools/htsjdk/issues/1689 + //{withHttpPath.toUri().toString(), new String[]{".vcf", ".vcf.gz"}, 4} }; } diff --git a/src/test/resources/htsjdk/samtools/io/FofnWithHttpQueryParams.fofn b/src/test/resources/htsjdk/samtools/io/FofnWithHttpQueryParams.fofn new file mode 100644 index 0000000000..bd064892fe --- /dev/null +++ b/src/test/resources/htsjdk/samtools/io/FofnWithHttpQueryParams.fofn @@ -0,0 +1,3 @@ +src/test/resources/htsjdk/samtools/io/Level1.fofn +http://www.example.com/blurg.vcf +http://www.example.com/blurg.vcf?huh=bleep,bloop