samtools / htsjdk

A Java API for high-throughput sequencing data (HTS) formats.
http://samtools.github.io/htsjdk/
283 stars 242 forks source link

Handle spaces in input strings in Tabix and SeekableStreamFactory. #1487

Closed cmnbroad closed 4 years ago

cmnbroad commented 4 years ago

Fix exceptions when trying to create a VCFFileReader on a VCF/.tbi when they're located in a path that contains spaces in the name (see https://github.com/broadinstitute/gatk/issues/6664).

The exception is caused by asymmetric assumptions about the encoding of the input string in different layers. This code in VCFFileReader converts the input path to a Uri, and the resulting url-encoded String is passed on, but there is downstream code in SeekableStreamFactory.getStreamFor here that doesn't decode the String, and tries to use the encoded version with the File constructor, which fails because File wants the non-encoded path.

The fix is to decode the input String in SeekableStreamFactory before passing it on to the File constructor (for some reason, calling getPath on a URI returns a decoded string, but getPath on a URL doesn't). Both of the new tests included here fail without this change.

codecov-commenter commented 4 years ago

Codecov Report

Merging #1487 into master will increase coverage by 0.011%. The diff coverage is 50.000%.

@@               Coverage Diff               @@
##              master     #1487       +/-   ##
===============================================
+ Coverage     69.235%   69.246%   +0.011%     
- Complexity      8721      8723        +2     
===============================================
  Files            588       588               
  Lines          34620     34623        +3     
  Branches        5787      5787               
===============================================
+ Hits           23969     23975        +6     
+ Misses          8367      8366        -1     
+ Partials        2284      2282        -2     
Impacted Files Coverage Δ Complexity Δ
...samtools/seekablestream/SeekableStreamFactory.java 72.000% <50.000%> (-5.273%) 6.000 <0.000> (ø)
...samtools/util/AsyncBlockCompressedInputStream.java 76.000% <0.000%> (+4.000%) 13.000% <0.000%> (+1.000%)
...htsjdk/samtools/util/nio/DeleteOnExitPathHook.java 90.476% <0.000%> (+9.524%) 4.000% <0.000%> (+1.000%)