urlencode()'ed url's which are local to the site are being double urlencode()'ed when used.

Created on 27 October 2023, 11 months ago
Updated 13 March 2024, 6 months ago

Problem/Motivation

local url's which are added to textarea are becoming broken if the used URL is url encoded. And in some cases this is happening with CKEditor encoding url's when adding a link.

A url like https://local.site/sites/default/files/test%20file.txt will then get converted to a URI like base:sites/default/files/test%20file.txt which is stored.

Now it is stored with the encoding since since it is a local url it gets converted to a schema of base or internal, which during the route assembly/generator in the Url() it will call rawurlencode() and the url will be double encoded resulting in base:sites/default/files/test%2520file.txt

Steps to reproduce

Create content with a link to a local file which has a space. once saved, redisplaying the link will result in a double encoding.

Proposed resolution

During the normalisation of the URL, if it is an internal url (prefixed with base: internal: entity:) run the url though rawurldecode()

Also note i was only able to test this on Drupal 10. I do not have a D9 environment to see if this happens there as well.

🐛 Bug report
Status

Needs review

Version

2.0

Component

Code

Created by

🇦🇺Australia gordon Melbourne

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

Comments & Activities

  • Issue created by @gordon
  • Status changed to Needs review 11 months ago
  • Open in Jenkins → Open on Drupal.org →
    Core: 10.1.4 + Environment: PHP 8.1 & MySQL 8
    last update 11 months ago
    38 pass
  • 🇦🇺Australia gordon Melbourne

    Here is a patch to fix this. I also added a post update which will check all the existing links and url decode them.

  • 🇦🇺Australia gordon Melbourne

    I found that the post update didn't have the correct function name, (it was using the template version) and also cleaned up the comment to why we need to do this in the code.

    Also I have moved this into a repository which will make it easier to check,

Production build 0.71.5 2024