Skip to content
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

Never generate empty filename for download #561

Merged
merged 1 commit into from
Jul 27, 2020
Merged

Conversation

christopher-dG
Copy link
Member

Ran into a strange error when I was trying HTTP.download, it tried to save the file to /tmp/, which obviously is not a valid path for a file. Found out that the Content-Disposition header listed an empty filename which is... odd.

julia> using HTTP

julia> resp = HTTP.get("https://pretalx.com/media/juliacon2020/images/9A8DCP/logo_kafyqWH.png");

julia> println(HTTP.header(resp, "Content-Disposition"))
attachment; filename=""

I could add this to the test suite but I'm afraid of the URL not being very permanent. Thoughts on that?

@codecov-commenter
Copy link

codecov-commenter commented Jul 26, 2020

Codecov Report

Merging #561 into master will decrease coverage by 0.09%.
The diff coverage is 0.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #561      +/-   ##
==========================================
- Coverage   77.52%   77.43%   -0.10%     
==========================================
  Files          37       37              
  Lines        2096     2096              
==========================================
- Hits         1625     1623       -2     
- Misses        471      473       +2     
Impacted Files Coverage Δ
src/download.jl 0.00% <0.00%> (ø)
src/IOExtras.jl 64.28% <0.00%> (-3.58%) ⬇️
src/ConnectionPool.jl 77.63% <0.00%> (-0.43%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update abc5d3d...1934527. Read the comment docs.

@@ -29,7 +29,7 @@ function try_get_filename_from_headers(resp)
# It was in quotes, so it will be double escaped
filename = unescape_string(quoted_filename[1])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unrelated to this PR, but is quoted_filename[1] valid? I don't think that works when doing match, because it returns a RegexMatch object, right? So trying to index it is going to be an error? Am I missing something here?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

RegexMatches are indexable:

julia> match(r"(x)(y)", "xyz")[1]
"x"

julia> match(r"(x)(y)", "xyz")[2]
"y"

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, my confusion was missing the match groups in the regex. Thanks.

@quinnj quinnj merged commit 7dfbf55 into master Jul 27, 2020
@quinnj quinnj deleted the cdg/download-filename branch July 27, 2020 13:35
@StefanKarpinski
Copy link
Contributor

Is it possible that this is because you can open a directory these days and it acts like an empty file? That is a bug: JuliaLang/julia#36605.

@christopher-dG
Copy link
Member Author

I'm guessing it was totally unintentional, having a filename set in Content-Disposition as explicitly empty seems like an edge case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants