Skip to content

BUGFIX: Compare hosts when checking if target and source are the same#106

Open
robinroloff wants to merge 1 commit intoneos:mainfrom
robinroloff:bugfix/same-path-different-host
Open

BUGFIX: Compare hosts when checking if target and source are the same#106
robinroloff wants to merge 1 commit intoneos:mainfrom
robinroloff:bugfix/same-path-different-host

Conversation

@robinroloff
Copy link

This PR fixes the "sameSourceAndTarget" and check. Previously, it was not correctly comparing the source and target host.

On the frontend, it was comparing the sourceHost to the host the user is currently on:

if (!host || host === location.host) {

This also had the unwanted side effect that this check would only work when the user is creating a redirect for the very same domain they are currently on (most of the time the primary site). When they were creating a redirect for another site, this would only be checked on the backend and give the user a generic error "Redirect could not be created".

And on the backend, it was creating the redirect using the $host variable:

$redirect = $this->redirectStorage->getOneBySourceUriPathAndHost($sourceUriPath, $host ?: null, false);

and then comparing it against itself:

$isSame = $this->isSame($sourceUriPath, $targetUriPath, $host, $statusCode, $redirect);

Example:

Domain: www.foo.bar
Source Path: test
Target Path: www.example.com/test

Before: This throws an error
Now: Works as expected

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant