Linkit Link field: Double-encoded file links

Created on 28 March 2024, 6 months ago
Updated 16 May 2024, 4 months ago

Problem/motivation

This is related to this closed issue πŸ› Linkit Link field: File entities not processed like other entities, resulting in double-encoding Fixed . We are encountering the issue of double-encoded links for file entities with 6.1.3 using the Linkit widget with a core formatter, in this case the Separate link text and URL formatter.

Steps to reproduce

  1. install Linkit 6.1.x-dev
  2. Upload a file/media with a space in the name
  3. Edit the basic page content type, add a link field with default settings but change the form display to use the linkit widget, change the display to use a non-linkit formatter like Separate link text and URL
  4. Create a page using the basic page content type and link to the file/media with the link field.
  5. On the edit page the link will appear like this: /sites/default/files/2023-03/name%20with%20space.pdf
  6. When the page is saved and viewed the link will appear like this: /sites/default/files/2023-03/name%2520with%2520space.pdf

Proposed resolution

If core link formatters expect a decoded url then it seems ideal that the Linkit widget should take care of decoding the url. I'm not sure if there is a better way to accomplish that but I am attaching a patch that adds an urldecode() step in MassageFormValues() in LinkWidget.

This module uses Gitlab CI for automated testing of proposed code changes. To contribute code changes, create a merge request. Patch files will not trigger automated testing and are not sufficient for review.
πŸ› Bug report
Status

Needs review

Version

7.0

Component

Code

Created by

πŸ‡¨πŸ‡¦Canada Laura Johnson Toronto

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

Comments & Activities

  • Issue created by @Laura Johnson
  • πŸ‡¨πŸ‡¦Canada Laura Johnson Toronto
  • Status changed to Needs review 6 months ago
  • πŸ‡ΊπŸ‡ΈUnited States vinmassaro
  • πŸ‡ΊπŸ‡ΈUnited States codechefmarc

    I was just trying out this patch and noticed that if there isn't a value passed to the urldecode function on line 220, it will give an error message about a required parameter. I suggest adding the following:
    $value['uri'] = $uri ? urldecode($uri) : ''; or $value['uri'] = $uri ? urldecode($uri) : NULL; - I haven't dug too deep into if the $value['uri] needs to be an empty string or a NULL.

  • πŸ‡¨πŸ‡¦Canada TheDuke13

    Here's a patch with the fix mentioned, encountered this issue with a site where we got a deprecation warning that passing NULL as parameter #1 to urldecode() triggers a deprecated warning, so checking to ensure it's not empty would be important.

  • πŸ‡ΊπŸ‡ΈUnited States mark_fullmer Tucson
Production build 0.71.5 2024