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

Properly parse the content disposition filename #46

Merged
merged 1 commit into from
Nov 22, 2024

Conversation

juntyr
Copy link
Contributor

@juntyr juntyr commented Oct 31, 2024

If the content disposition header filename uses quotes, pyodide-build includes the quotes in the literal filename, which e.g. confuses shutil.unpack_archive in determining the file type.

This PR includes a simple fix to check and strip the quotes uses the email.message.Message parser to properly extract the filename (see https://stackoverflow.com/a/78073510).

The PR should be squashed (the first commit is overriden by the second one).

@hoodmane
Copy link
Member

Add a test please?

@juntyr
Copy link
Contributor Author

juntyr commented Nov 2, 2024

Add a test please?

What kind of test would you like? There's one static lib package in my fork that triggers the problem, but of course their server could stop wrapping the filename in quotes altogether. We could also extract the header parsing into a helper function and unit test it - if so I could also expected failure tests for other cases of the header that aren't handled yet (until someone else needs them).

Alternatively, is there some library that could do the header parsing for us so we don't need these half-baked fixes?

@juntyr juntyr changed the title Strip optional quotes from content disposition filename Properly parse the content disposition filename Nov 22, 2024
@juntyr
Copy link
Contributor Author

juntyr commented Nov 22, 2024

Add a test please?

@hoodmane We're now using the email.message.Message parser and no custom logic anymore. Would you still like a test? I checked that all cases in https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Disposition are properly handled by this standard library package.

@juntyr juntyr force-pushed the download-content-disposition branch from f29a8fc to 3e3ffe4 Compare November 22, 2024 07:51
@hoodmane
Copy link
Member

It would still be good to have a test, particularly because it sounds like it will be quite simple. If there is some reason that adding a test would be very hard it can be omitted but that doesn't seem to me to be the case here.

Copy link
Member

@hoodmane hoodmane left a comment

Choose a reason for hiding this comment

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

Thanks!

@hoodmane
Copy link
Member

Just have to fix pre-commit...

Use the email.message.Message parser

Refactor into _extract_tarballname helper function

Add a small unit test
@juntyr juntyr force-pushed the download-content-disposition branch from 4503b4a to cb850bc Compare November 22, 2024 11:50
@juntyr
Copy link
Contributor Author

juntyr commented Nov 22, 2024

@hoodmane This should now be good to go :)

@hoodmane hoodmane merged commit eb09824 into pyodide:main Nov 22, 2024
4 checks passed
@hoodmane
Copy link
Member

Thanks @juntyr!

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.

3 participants