Closed Bug 1606300 Opened 4 years ago Closed 4 years ago

When saving a video with a URL Encoded filename, it's saved with the encoded (rather than decoded) file name

Categories

(Toolkit :: Downloads API, defect, P1)

71 Branch
defect

Tracking

()

RESOLVED FIXED
mozilla74
Tracking Status
firefox74 --- fixed

People

(Reporter: strannick, Assigned: Gijs)

References

Details

Attachments

(1 file)

User Agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:71.0) Gecko/20100101 Firefox/71.0

Steps to reproduce:

  1. go to URL https://files.rokiroki.ru/ff/Nemnogo%20Nervno%20-%20%D0%98%D1%81%D1%82%D0%B8%D0%BD%D0%BD%D0%BE%D0%B5%20%D0%B2%D0%BE%D0%BB%D1%88%D0%B5%D0%B1%D1%81%D1%82%D0%B2%D0%BE.mp4

  2. press "Save video as…"

Actual results:

the filename suggested by Firefox looks like:

Nemnogo%20Nervno%20-%20%D0%98%D1%81%D1%82%D0%B8%D0%BD%D0%BD%D0%BE%D0%B5%20%D0%B2%D0%BE%D0%BB%D1%88%D0%B5%D0%B1%D1%81%D1%82%D0%B2%D0%BE.mp4

Expected results:

the filename suggested by Firefox looks like:

Nemnogo Nervno - Истинное волшебство.mp4

Bugbug thinks this bug should belong to this component, but please revert this change in case of error.

Component: Untriaged → Audio/Video: Playback
Product: Firefox → Core

Example:

  1. URL https://files.rokiroki.ru/Nemnogo%20Nervno%20-%20%D0%98%D1%81%D1%82%D0%B8%D0%BD%D0%BD%D0%BE%D0%B5%20%D0%B2%D0%BE%D0%BB%D1%88%D0%B5%D0%B1%D1%81%D1%82%D0%B2%D0%BE.mp4 — all right

  2. URL https://files.rokiroki.ru/ff/Nemnogo%20Nervno%20-%20%D0%98%D1%81%D1%82%D0%B8%D0%BD%D0%BD%D0%BE%D0%B5%20%D0%B2%D0%BE%D0%BB%D1%88%D0%B5%D0%B1%D1%81%D1%82%D0%B2%D0%BE.mp4 — trouble.

What the difference?
in the second URL web-server sends HTTP-header:
Content-Disposition 'inline; filename="Nemnogo%20Nervno%20-%20%D0%98%D1%81%D1%82%D0%B8%D0%BD%D0%BD%D0%BE%D0%B5%20%D0%B2%D0%BE%D0%BB%D1%88%D0%B5%D0%B1%D1%81%D1%82%D0%B2%D0%BE.mp4"';

I think Firefox must decode URL Encoded filename from Content-Disposition header.

I don't think this is a media issue, moving to Firefox in the hope it can find the correct home.

Component: Audio/Video: Playback → General
Product: Core → Firefox

The priority flag is not set for this bug.
:Dolske, could you have a look please?

For more information, please visit auto_nag documentation.

Flags: needinfo?(dolske)

Valentin, do you know what the current spec is for this, and is URL encoding normal for the contents of this header (see comment #2) ? (I believe we rely on https://searchfox.org/mozilla-central/rev/ad6234148892bc29bf08d736604ac71925138040/netwerk/base/nsNetUtil.cpp#2656 so moving to networking...)

Component: General → Networking
Flags: needinfo?(dolske) → needinfo?(valentin.gosu)
Product: Firefox → Core
Summary: When I try to save video with URL Encoded filename, it saving with wrong filename → When saving a video with a URL Encoded filename, it's saved with the encoded (rather than decoded) file name

(In reply to :Gijs (he/him) from comment #5)

Valentin, do you know what the current spec is for this, and is URL encoding normal for the contents of this header (see comment #2) ? (I believe we rely on https://searchfox.org/mozilla-central/rev/ad6234148892bc29bf08d736604ac71925138040/netwerk/base/nsNetUtil.cpp#2656 so moving to networking...)

I haven't actually found where we actually get the filename from but returning an arbitrary string from HttpBaseChannel::GetContentDispositionFilename or NS_GetFilenameFromDisposition doesn't change the suggested filename.

Gijs, can you happen to know where that happens?

Flags: needinfo?(gijskruitbosch+bugs)

(In reply to Valentin Gosu [:valentin] (he/him) from comment #6)

(In reply to :Gijs (he/him) from comment #5)

Valentin, do you know what the current spec is for this, and is URL encoding normal for the contents of this header (see comment #2) ? (I believe we rely on https://searchfox.org/mozilla-central/rev/ad6234148892bc29bf08d736604ac71925138040/netwerk/base/nsNetUtil.cpp#2656 so moving to networking...)

I haven't actually found where we actually get the filename from but returning an arbitrary string from HttpBaseChannel::GetContentDispositionFilename or NS_GetFilenameFromDisposition doesn't change the suggested filename.

Gijs, can you happen to know where that happens?

Err, embarrassingly, no, I'm not sure off-hand - I thought it was from https://searchfox.org/mozilla-central/rev/2e355fa82aaa87e8424a9927c8136be184eeb6c7/uriloader/exthandler/nsExternalHelperAppService.cpp#714 ?

I also just realized I cannot reproduce this in nightly right now. Perhaps I could at the time, and something has changed in the website? Reporter, are you still seeing this problem? Can you try with a build from https://nightly.mozilla.org/ and confirm whether it shows the same behaviour?

Flags: needinfo?(gijskruitbosch+bugs) → needinfo?(strannick)

I'm download nightly from here:
https://download.mozilla.org/?product=firefox-nightly-latest-l10n-ssl&os=linux64&lang=ru

It is a firefox-74.0a1.ru.linux-x86_64.tar.bz2

Next, I going to links and check it.

  1. All right, like ordinary FF.
  2. Trouble, like ordinary FF.

And I see somethung, what may help you to see whats wrong. Looks here:


P.S. if images not shows:

  1. All right. Video saves with right filename: https://files.rokiroki.ru/ff-all-right.png
  2. Wrong. Video saves with bad filename: https://files.rokiroki.ru/ff/ff-bad-luck.png

Hope, it helps.

Flags: needinfo?(strannick)

It's still happening for me with both STR in comment 2 and comment 8.

Gijs, I've found the code that suggests the filename for saveAs - it's contentAreaUtils.js::getDefaultFileName

The codepath is either internalSave > initFileInfo > getDefaultFileName or DownloadURL > initFileInfo > getDefaultFileName
We seem to be unescaping it in some cases but not others

Component: Networking → Downloads API
Flags: needinfo?(valentin.gosu) → needinfo?(gijskruitbosch+bugs)
Product: Core → Toolkit

OK, it seems there are two codepaths and they're both broken.

If you open https://files.rokiroki.ru/ff/Nemnogo%20Nervno%20-%20%D0%98%D1%81%D1%82%D0%B8%D0%BD%D0%BD%D0%BE%D0%B5%20%D0%B2%D0%BE%D0%BB%D1%88%D0%B5%D0%B1%D1%81%D1%82%D0%B2%D0%BE.mp4

and:

  1. hit accel-s / save page as shortcut.

This hits getDefaultFileName but actually takes the passed aContentDisposition, reads the header parameter using the mime header param service ( https://searchfox.org/mozilla-central/rev/2e355fa82aaa87e8424a9927c8136be184eeb6c7/toolkit/content/contentAreaUtils.js#1179-1201 ) and returns that, without URL escaping.

  1. right click the video, click "save video as"

This goes via saveMedia in nsContextMenu.js and uses the webbrowserpersist code, which hits the nsNetUtil code. If I return garbage in there, both the tab title and the offered filename in here use that garbage.

Assignee: nobody → gijskruitbosch+bugs
Status: UNCONFIRMED → ASSIGNED
Ever confirmed: true
Flags: needinfo?(gijskruitbosch+bugs)

The getDefaultFileName helper function does its own filename parsing using header info
it has previously 'manually' retrieved, so it needs to manually unescape its input.

Meanwhile, NS_GetFilenameFromDisposition is used by webbrowserpersist and for
the title of documents, and so updating that helps ensure better UI as well as
correct filename suggestions when saving from the context menu.

Priority: -- → P1
Pushed by gijskruitbosch@gmail.com:
https://hg.mozilla.org/integration/autoland/rev/ab6076376754
escape filenames in tab titles, save as... dialog and as used by webbrowserpersist, r=valentin
Status: ASSIGNED → RESOLVED
Closed: 4 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla74
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: