-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
fix incorrect encoding of filenames with spaces in #2090
Conversation
btw, it looks like this never particularly deliberately special-cased non-utf8; when Mjark added utf8 support in #259 he just left the original code path alone, assuming it worked.
bah, guess i need to fix the tests. will wait for PR review first |
matrix-org/sytest#350 should cheer up sytest. |
Given the compatibility problems I wonder if it would be a good idea to only use the utf8 foo when we need it? Also, I wonder if we should start giving out the url with the filename at the end: e.g. https://jki.re/_matrix/media/v1/download/matrix.org/zFHVTzeUHJnsbomaeHEehfSI/matthew.jpg |
i don't think any modern browsers have compatibility problems with the utf-8 encoding? or is there something specific i'm missing? is your proposal to only use the utf-8 encoding if the filename includes spaces, then? this feels magical and fragile; we don't want it randomly breaking in weird ways on files with spaces - they surely shouldn't be special-cased at all. Agreed that it might be nicer to switch to putting the filename on the end of the URL as the most reliable solution, but i think this one actually works? |
this is getting really annoying, my downloads folder is filling up with files with beautiful names like |
@matrixbot retest this please |
empirically my Downloads folder is no longer filling up with |
I suspect you've updated to a more recent version of Chrome, which (incorrectly, afaict) decodes the %-encoding in the filename. This is still a bug on Firefox, at least as of 62.0 |
for the record: RFC6266 defines both
So the fix in this PR is correct inasmuch as it means we always use the |
however, I am minded to think that we should instead fix the escaping used in the |
Codecov Report
@@ Coverage Diff @@
## develop #2090 +/- ##
============================================
- Coverage 75.08% 58.58% -16.51%
============================================
Files 340 324 -16
Lines 34895 33769 -1126
Branches 5717 5576 -141
============================================
- Hits 26201 19782 -6419
- Misses 7080 12609 +5529
+ Partials 1614 1378 -236 |
I've substantially rewritten this, so a sanity-check from someone else on the team would be appreciated. I suggest just looking at the diff, which should speak for itself, rather than trying to pick your way through the history. Tests at matrix-org/sytest#350. |
synapse/rest/media/v1/_base.py
Outdated
# [2]: https://tools.ietf.org/html/rfc2616#section-3.6 | ||
# [3]: https://tools.ietf.org/html/rfc5987#section-3.2.1 | ||
|
||
# We avoid the quoted-string version of filename, because (a) synapse didn't |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i'd suggest saying `filename` here, to make it clear you're talking about `filename` rather than `filename*`
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
point, done
# correctly interpret those as of 0.99.2 and (b) they are a bit of a pain and we | ||
# may as well just do the filename* version. | ||
if _can_encode_filename_as_token(upload_name): | ||
disposition = 'inline; filename=%s' % (upload_name, ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why not do filename* everywhere?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the main thinking is that some things won't have good support for filename
, and we should cater to simple clients where possible.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you mean good support for filename*
?
okay, fair enough.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sorry, yes that's what I mean.
…server_specific_tests * 'develop' of github.com:matrix-org/sytest: (44 commits) test endpoint for updating backup versions (#559) Add test for transferring bans on a room upgrade (#563) fix tests for matrix-org/synapse#2090 (#350) Fix typo Fixup Incorporate review Remove prev_state from federation API Make the userdir synced not rely on being able to search for yourself (#567) Add basic soft fail test Check that event_id is given over state fetching over federation (#566) Fix registration rate limiting settings Fix comments Make sytest support auth rate limiting Fixup to not send 100 messages Test history visibility works for backfill Check that Server ACLs are preserved on room upgrade Better diagnostics from synapse startup (#561) Don't set PYTHONPATH when running synapse (#560) Regression test for redactions in room v3 (#558) Add test for PDU limit on transactions API (#555) ...
fixing element-hq/element-web#3155