Page MenuHomePhabricator

Core REST API create endpoint generates URLs with improper encoding of spaces
Closed, ResolvedPublic

Description

The create page endpoint returns a Location: header with the full URL of the API endpoint for the new page.

If the title of the page includes a space (" "), the URL in the Location: header encodes it as a plus ("+").

When the client retrieves the URL in the Location: header, the router is unable to find the title with the +, and returns a 404.

There are two tasks for this issue, based on the robustness principle:

  • Encode spaces with the preferred underscore ("_") instead of plus ("+")
  • Consider accepting plus ("+") as an encoding for spaces when parsing page titles in the REST API

If the second one isn't possible (Because "+" is a valid character in MW page titles; I think there's been a long controversy about this, so my guess is probably not), we should make sure that it's documented.

Event Timeline

Consider accepting plus ("+") as an encoding for spaces when parsing page titles in the REST API

This would cause confusion, because "+" is actually an allowed character in page titles, and used in paths. We support it in the URLs for human readable pages, and should also support it in REST urls. Consider https://en.wikipedia.org/wiki/C++. See also https://stackoverflow.com/questions/2678551/when-to-encode-space-to-plus-or-20

Change 615548 had a related patch set uploaded (by Daniel Kinzler; owner: Daniel Kinzler):
[mediawiki/core@master] REST /page/{title}: Fix title encoding.

https://gerrit.wikimedia.org/r/615548

Made a patch that should fix the issue. Found a number of related issues with tests along the way.

Change 615548 merged by jenkins-bot:
[mediawiki/core@master] REST /page/{title}: Fix title encoding.

https://gerrit.wikimedia.org/r/615548

Clarakosi reassigned this task from Clarakosi to daniel.
Clarakosi subscribed.

Change 617127 had a related patch set uploaded (by Reedy; owner: Daniel Kinzler):
[mediawiki/core@REL1_35] REST /page/{title}: Fix title encoding.

https://gerrit.wikimedia.org/r/617127

Change 617127 merged by jenkins-bot:
[mediawiki/core@REL1_35] REST /page/{title}: Fix title encoding.

https://gerrit.wikimedia.org/r/617127