Add support for encoded URLs (with spaces or other special characters)

Created on 8 June 2017, over 7 years ago
Updated 12 August 2024, 4 months ago

I ran into issue when source url was like this: en/products/tshirts/black+and+white/ from old site and was need to redirect to new store. But there were problem with this because Drupal received url without these "+" just with spaces between. Therefore hash that is stored in DB did not matched with source urls hash..

I created really quick and easy solution in patch, everyone welcome to create better and more Drupal way solution.

✨ Feature request
Status

Needs work

Version

1.0

Component

Code

Created by

πŸ‡±πŸ‡»Latvia maris.abols

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.

  • πŸ‡ΊπŸ‡ΈUnited States dpagini

    +1 for this patch, it solves the same problem I'm facing... Url's in the "From" field with a special character, like `path/to/a%20file.pdf` won't work.
    This issue has been RTBC for almost a year now, is there anything left the maintainers need on this issue? I see that, it appears, the last requested changes by Berdir were completed, so I think this just needs eyes again from an maintainer.

  • Status changed to Needs work almost 2 years ago
  • πŸ‡¨πŸ‡­Switzerland berdir Switzerland

    I'm concerned about the upgrade path. I maintain sites with tens and hundreds of thousands of redirects, a forced upgrade path that will recalculate the hash for all of them is going to take time and could possibly mean quite a long downtime for a site of that size. What about adding a button to the settings page to do recalculate hashes, and the update function could just add a message that people might want to run that? We could reuse that if other changes need to happen.

    The cache tag handling is also not correct, the list cache tag is mostly just for render caching, the entity storage will still cache those entries, should either invalidate them all through EntityStorageInterface::resetCache() or alternatively the specific entities that are being changed here.

    +++ b/tests/src/Kernel/RedirectAPITest.php
    @@ -62,6 +62,10 @@ class RedirectAPITest extends KernelTestBase {
         $this->assertEquals(Redirect::generateHash('some-url', ['key1' => 'val1'], Language::LANGCODE_NOT_SPECIFIED), $redirect->getHash());
    +    // Update the redirect source with a + sign in it.
    +    $redirect->setSource('some+url');
    +    $redirect->save();
    +    $this->assertEquals(Redirect::generateHash('some url', [], Language::LANGCODE_NOT_SPECIFIED), $redirect->getHash());
         // Update the redirect source path and check if hash has been updated as
    

    this isn't testing much because it would also pass on HEAD, it's just testing that the hash is generated. We probably want to hardcode the hash for that case.

  • πŸ‡ΊπŸ‡ΈUnited States richardbporter

    Rerolled #25 for 8.x-1.9.

  • πŸ‡ΊπŸ‡¦Ukraine cmd87

    Uploading the patch for version 8.x-1.10

Production build 0.71.5 2024