Duplicate urlencode when redirect to Token target

Created on 29 August 2018, almost 6 years ago
Updated 14 November 2023, 8 months ago

I ran into an issue when setting a Page Redirect in a content type.
My content type, callled Document, has a Media Entity reference field (field_file) to allow user to upload files (e.g. PDF, DOC, DOCX). I set a Page Redirect when accessing the Document content type to redirect to the media file from field_file, using the following token:

[node:field_file:entity:field_media_file]

Redirect works fine, except when the file name has a space, for instance "my document.pdf". In this case, the user is redirect to a nonexisting page. For instance:

Correct (expected) file path:
/sites/default/files/documents/my%20document.pdf

Given file path:
/sites/default/files/documents/my%2520document.pdf

What's happening here is that the received token target is already urlencoded, and as long as the path isn't external, the function toString() on line 173 apparently urlencodes target again, replacing % for %25 (ASCii code for percent symbol).

I created a patch which undoes the token urlencoding (using rawurldecode(), preventing the duplication. Of course, it needs review, especially for more complex cases such as multilingual sites.

πŸ› Bug report
Status

Fixed

Component

Code

Created by

πŸ‡¨πŸ‡¦Canada maursilveira Windsor, ON

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • πŸ‡§πŸ‡ͺBelgium gillesv

    This is still an issue in the latest versions of Rabbit Hole 1.x and 2.x
    When there are spaces in the filename, and you try to redirect to it (via [node:field_file] for example), it double encodes the URL resulting in a "Page not found" error.

    @jimafisk ' s solutions to replace "PlainTextOutput::renderFromHtml" with "rawurldecode" in PageRedirect.php seems to fix the problem.

Production build 0.69.0 2024