distantnative / retour-for-kirby

Kirby CMS plugin to manage redirects and track 404s right from the Panel
https://distantnative.com/retour-for-kirby/
MIT License
135 stars 15 forks source link

[BUG] 404 when trying to "Add as redirect" in "Failures" #307

Closed ieteo closed 2 years ago

ieteo commented 2 years ago

Describe the bug

The release 4.2.0 fixed the bug #300 when editing or removing path containing slashes from "Routes". Thank you!

However, the bug is still present when trying to "Add as redirect" from "Failures", which results in 404 error as described in #300

This bug is only present on Apache when the AllowEncodedSlashes is set to Off

Steps to reproduce

  1. Get the Kirby starter kit and instal distantnative/retour-for-kirby
git clone https://github.com/getkirby/starterkit.git
cd starterkit
composer require distantnative/retour-for-kirby
  1. Create Dockerfile with following content

    FROM php:8.1-apache
    RUN a2enmod rewrite
  2. Build image and run the container

    docker build -t starterkit .
    docker run -p 80:80 -v "$PWD":/var/www/html starterkit
  3. Call a non-existent URL containing slashes e.g. http://localhost/sub/not-existing

  4. Go to http://localhost/panel, create user and log in

  5. Go to Rredirect > Failures and Add as redirect the previously called non-existent URL

Result: 404 Not Found from Apache

Note Removing path containing slashes under Failures also results in 404 error

Expected behavior

modal opens up in order to add the path as redirect

Context

distantnative commented 2 years ago

🙈

ieteo commented 2 years ago

I assume that changing this line:

https://github.com/distantnative/retour-for-kirby/blob/b74f5473f33603b7a1bfdaa1c9716b03998202b6/src/panel/components/Tabs/FailuresTab.vue#L65

to: const path = encodeURIComponent(row.path.replace(/\//g, "\x1D"));

as what was done in: https://github.com/distantnative/retour-for-kirby/blob/b74f5473f33603b7a1bfdaa1c9716b03998202b6/src/panel/components/Tabs/RedirectsTab.vue#L103

would hopefully also fix it in FailuresTab

EDIT:

The above alone won fix the issue.

In order to fix it, I had to changed the above and also change this line:

https://github.com/distantnative/retour-for-kirby/blob/b74f5473f33603b7a1bfdaa1c9716b03998202b6/src/extensions/dialogs.php#L142

to: 'from' => str_replace("\x1D",'/', urldecode($path))

distantnative commented 2 years ago