Page MenuHomePhabricator

Electron incorrectly creating file name with apostrophes
Closed, ResolvedPublic

Description

Background

reported by user: https://www.mediawiki.org/wiki/Topic:Tv01r0b9t13e0zti

Steps to recreate

  1. Go to article for Hubble's Law (https://en.wikipedia.org/wiki/Hubble's_law)
  2. Save article as PDF using electron (single-column)

Expected behavior
file name should be "Hubble's_law)
Observed behavior
file name saves as "'s law"

Note: also reproduced with:
https://en.wikipedia.org/wiki/Newton%27s_laws_of_motion
https://en.wikipedia.org/wiki/Kepler%27s_laws_of_planetary_motion

Event Timeline

GWicke triaged this task as Medium priority.
GWicke edited projects, added Services (doing); removed Services.

Checking https://en.wikipedia.org/api/rest_v1/page/pdf/Hubble's_law, the returned content-disposition header shows attachment; filename=Hubble's_law.pdf; filename*=Hubble's_law.pdf. At least the second half of this looks broken, and causes Chrome to suggest the file name "Hubble's_law.pdf; filename-=Hubble's_law.pdf" when saving. Firefox however suggests s_law.pdf, which matches the task description.

https://tools.ietf.org/html/rfc5987#section-3.2.2 shows an example for a correct extended attribute encoding: foo: bar; title*=UTF-8''%c2%a3%20and%20%e2%82%ac%20rates. The encoding parameter is mandatory, and the delimiter is an apostrophe ('). This explains why Firefox cuts off the name.

At least for the regular filename parameter, we should also use the quoted string syntax described in https://tools.ietf.org/html/rfc2616#section-2.2.

The fix has been deployed, and I verified that the test cases are working now.