download-manager icon indicating copy to clipboard operation
download-manager copied to clipboard

Problem with URL containing query string

Open lkaminskivim opened this issue 4 years ago • 4 comments

Hi,

When url contains query params (?name=val&...), then entire query string is included in file name. This is because FileNameExtractor.java keeps everything after last "/".

This leads FilePathCreator.java to create wrong path. This is because it eliminates redundant part of path using String.replaceAll method which treats its argument as regex. So in case of file name already containing query params (which contains special signs) it results in path like:

{intended_path_to_file}?{query_string}/{intended_path_to_file}?{query_string}

lkaminskivim avatar Jul 07 '19 12:07 lkaminskivim

Thank you very much for letting us know. We'll try and fix this as soon as we are able 👍

Mecharyry avatar Jul 08 '19 07:07 Mecharyry

Just an FYI that you can workaround this issue in the meantime by using https://github.com/novoda/download-manager/blob/release/library/src/main/java/com/novoda/downloadmanager/BatchFileBuilder.java#L35 to specify the path and file name directly for a file rather than using the extractor.

Mecharyry avatar Jul 08 '19 07:07 Mecharyry

I would argue this isn't a responsibility of the library since there's a way to customise the creation of the filename 👻

Although it would be good to document the behaviour

ouchadam avatar Aug 30 '19 13:08 ouchadam

I think that it's the library responsibility to work correctly and the FileNameExtractor does not in all cases, because it can't handle properly urls with query parameters :) In order to fix the implementation, only one additional split is needed. Kotlin version below: assetUrl.split("/").last().split("?").first()

jakubvimn avatar Oct 10 '19 14:10 jakubvimn