ApiFormatBase: Encode filenames in Content-Disposition
authorBrad Jorsch <bjorsch@wikimedia.org>
Wed, 7 Feb 2018 20:12:33 +0000 (15:12 -0500)
committerBrad Jorsch <bjorsch@wikimedia.org>
Wed, 7 Feb 2018 20:12:33 +0000 (15:12 -0500)
commit7bc541a4a70899475b88daaf2f26db1e1fc5e18a
tree809892b2dbefe813b8231a1c2ccaa49d95646c00
parent5db74eb56e425ba803b2cc936fbe3e5cc219b482
ApiFormatBase: Encode filenames in Content-Disposition

The return value for ApiFormatBase::getFilename() was formerly
documented as "must be encoded for inclusion in a Content-Disposition
header's filename parameter." While this is ok for the common use case
where the module is returning a constant string or can assume whatever
it gets back from getExtensionsForType() is ok, it's not in general a
good idea to make all callers handle that.

Further, it's not possible to represent characters outside of the
ISO-8859-1 character set in a 'filename' parameter. You have to use
'filename*' to do that (see RFC 5987 and RFC 6266).

So, this patch changes the definition of getFilename() to remove the
encoding requirement, and adds code to properly convert and escape the
value for the 'filename' and (if necessary) 'filename*' parameters.

Note this may give unexpected results (double encoding) if any module
actually is returning an encoded filename. I don't see any such cases in
core or in extensions in Gerrit.

Change-Id: I0c2749a847b639f228efff4e1917a61612a1f7d1
includes/api/ApiFormatBase.php
tests/phpunit/includes/api/format/ApiFormatBaseTest.php