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.