Closed Bug 1768671 Opened 3 years ago Closed 3 years ago

PDF.js doesn't honour filenames without pdf file extension when saving the document locally (e.g. from fido's web billing portal)

Categories

(Firefox :: PDF Viewer, defect, P3)

Desktop
All
defect

Tracking

()

VERIFIED FIXED
104 Branch
Tracking Status
firefox-esr102 --- verified
firefox102 --- wontfix
firefox103 --- wontfix
firefox104 --- verified

People

(Reporter: Gijs, Assigned: Gijs)

References

Details

Attachments

(3 files)

See earlier comments in bug 1767321.

Apparently this is still not fixed in Nightly 102.

I'll try and find someone who uses FIDO, where I can debug what's going on when I'm (all being well) in the Toronto office next week.

Someone who uses Rogers is probably fine too. I haven’t tested on my Rogers cable account, but Rogers owns Fido and I suspect the billing portal’s code is the same for both brands.

Comment on attachment 9275898 [details]
1768671.html

This is a test case from fido.ca. Looks similar to the code from this comment.

Per discussion with Ksenia, it seems that the difference between this and jscher's working testcase in bug 1756980 is the fact that the broken testcase doesn't specify a file extension (ie there's no ".pdf"), and the working one does.

This is an explicit exception in PDF.js: https://searchfox.org/mozilla-central/rev/5f88c1d6977e03e22d3420d0cdf8ad0113c2eb31/toolkit/components/pdfjs/content/PdfStreamConverter.jsm#350-355

ISTM we could just suffix .pdf if there is no file extension present at all. WDYT, Marco?

Component: File Handling → PDF Viewer
Flags: needinfo?(mcastelluccio)
Summary: Fido portal PDF downloads lose filename in PDF.js → PDF.js doesn't honour filenames without pdf file extension when saving the document locally (e.g. from fido's web billing portal)

Sounds good to me.

Flags: needinfo?(mcastelluccio)

The severity field is not set for this bug.
:calixte, could you have a look please?

For more information, please visit auto_nag documentation.

Flags: needinfo?(cdenizet)

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

This is an explicit exception in PDF.js: https://searchfox.org/mozilla-central/rev/5f88c1d6977e03e22d3420d0cdf8ad0113c2eb31/toolkit/components/pdfjs/content/PdfStreamConverter.jsm#350-355

I tried looking into this, and from what I could tell, data.filename is already "document.pdf" in PdfStreamConverter.jsm

The filename is passed to Firefox from PDF.js in firefoxcom.js

Following it back further, the filename is set at https://github.com/mozilla/pdf.js/blob/5d88233fbb11da28e155fa136d1abac0f7393f00/web/app.js#L768-L772

get _docFilename() {
  // Use `this.url` instead of `this.baseUrl` to perform filename detection
  // based on the reference fragment as ultimate fallback if needed.
  return this._contentDispositionFilename || getPdfFilenameFromUrl(this.url);
},

That's as far as I got. Maybe contentDispositionFilename isn't getting passed to PDF.js when there is a download attribute on an <a> element.

Severity: -- → S3
Flags: needinfo?(cdenizet)
Priority: -- → P3

The problem is actually in onOpenWithData. This function only sets _contentDispositionFilename iff the name ends with pdf. https://github.com/mozilla/pdf.js/blob/5d88233fbb11da28e155fa136d1abac0f7393f00/web/app.js#L718-L720

(In reply to Calixte Denizet (:calixte) from comment #11)

and as pointed out by :evilpie, this one has been added in:
https://github.com/mozilla/pdf.js/pull/13014

It seems that we have to relax the check in https://github.com/mozilla/pdf.js/blob/6ee538e0baee2434828efe97d9936f7ae436f5c6/web/app.js#L722 and replace it with something like this instead:

if (
  contentDispositionFilename &&
  typeof contentDispositionFilename === "string"
) {

:Snuffleupagus, wdyt about the Gijs' suggestion in https://bugzilla.mozilla.org/show_bug.cgi?id=1768671#c6 ?

That should work, as long as we take care to still exclude the isAttachment-case. Something like this could probably work:

if (!filename || typeof filename !== "string") {
  filename = "document";
}
if (!/\.pdf$/i.test(filename) && !data.isAttachment) {
  filename += ".pdf";
}
Flags: needinfo?(jonas.jenwald)

It just occurred to me that a potentially simpler solution overall, assuming it's not a terrible idea for some reason I'm overlooking, could be to append ".pdf" (if it's missing) already here:
https://searchfox.org/mozilla-central/rev/b1a5802e0f73bfd6d2096e5fefc2b47831a50b2d/toolkit/components/pdfjs/content/PdfStreamConverter.jsm#1133

Assignee: nobody → gijskruitbosch+bugs
Status: NEW → ASSIGNED
Pushed by gijskruitbosch@gmail.com: https://hg.mozilla.org/integration/autoland/rev/2cd3fe38c532 force append '.pdf' for pdf blob downloads displayed inline if it's missing, r=marco
Status: ASSIGNED → RESOLVED
Closed: 3 years ago
Resolution: --- → FIXED
Target Milestone: --- → 104 Branch

Since nightly and release are affected, beta will likely be affected too.
For more information, please visit auto_nag documentation.

Too late for uplift...

Did we want to get this on to ESR102 before users start migrating over from ESR91 in a couple weeks?

Flags: needinfo?(gijskruitbosch+bugs)

Comment on attachment 9285579 [details]
Bug 1768671 - force append '.pdf' for pdf blob downloads displayed inline if it's missing, r?marco

ESR Uplift Approval Request

  • If this is not a sec:{high,crit} bug, please state case for ESR consideration: Ergonomics fix for PDF downloads
  • User impact if declined: We ignore the name suggested by the server for some PDFs
  • Fix Landed on Version: 104
  • Risk to taking this patch: Low
  • Why is the change risky/not risky? (and alternatives if risky): 4 lines of JS code to handle a condition of a file not having a .pdf suffix, plus an automated test that covers this case so we won't regress it again.
Flags: needinfo?(gijskruitbosch+bugs)
Attachment #9285579 - Flags: approval-mozilla-esr102?

Comment on attachment 9285579 [details]
Bug 1768671 - force append '.pdf' for pdf blob downloads displayed inline if it's missing, r?marco

Approved for 102.3esr.

Attachment #9285579 - Flags: approval-mozilla-esr102? → approval-mozilla-esr102+
QA Whiteboard: [qa-triaged]

Verified as fixed in out latest 102.3.0esr and 104.0.2 on all platforms.

Status: RESOLVED → VERIFIED
Flags: qe-verify+
QA Whiteboard: [qa-triaged]
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: