Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect routing with setup.php based base #1892

Closed
hundblue opened this issue Feb 27, 2018 · 7 comments
Closed

Incorrect routing with setup.php based base #1892

hundblue opened this issue Feb 27, 2018 · 7 comments
Assignees

Comments

@hundblue
Copy link

hundblue commented Feb 27, 2018

There is an incorrect use of str_replace in Grav\Common\Uri::init():
[https://github.com/getgrav/grav/blob/eca23a918a71b0a49f5abad59e6c824f9e146351/system/src/Grav/Common/Uri.php#L321]($uri = str_replace($setup_base, '', $uri);).
The problem is that instead of removing just the prefix, each occurence of $setup_base is removed. For example, if the input $uri is equal to '/foo/bar/foo/baz' and $setup_base is equal to '/foo', then the output $uri is now equal to '/bar/baz'. The correct result should be '/bar/foo/baz'.

@rhukster
Copy link
Member

rhukster commented Mar 1, 2018

assigned to @mahagr to look at.

@rhukster rhukster added the bug label Mar 1, 2018
@mahagr
Copy link
Member

mahagr commented Mar 2, 2018

I just checked this and the behaviour is correct. It should do just that as the base path gets added to the urls by base_url variable in twig or by using url().

Uri is always relative to the site itself and is used in routing. If you want to point files outside of the site, you need to use absolute (or external) URLs.

@mahagr mahagr added by design and removed bug labels Mar 2, 2018
@hundblue
Copy link
Author

hundblue commented Mar 3, 2018

The behaviour which I have observed is that if the name of the subsite coincides with the name (the slug) of some page, then that page (or any of its subpages) is routed incorrectly.
For example, suppose 'foo' is the name of the subsite ('/foo' is then passed as $prefix to $container['pages']->base($prefix)). Furthermore, suppose that some page of the subsite is also named 'foo'. E.g., there is a page '05.bar' (under the 'pages' folder of the subsite) whose slug equals 'bar' and a page '05.bar/02.foo' whose slug equals 'foo'. Let $url be $hostname . '/foo/bar/foo'. Then this url is resolved to the 'bar' page instead of to the 'foo' page.

@hundblue hundblue closed this as completed Mar 3, 2018
@hundblue
Copy link
Author

hundblue commented Mar 3, 2018

Just pressed the wrong button, no intention to close the issue.

@hundblue hundblue reopened this Mar 3, 2018
@mahagr
Copy link
Member

mahagr commented Mar 12, 2018

Ok, I think I got it now.

You're saying that /foo/bar/foo will become /bar/ instead of /bar/foo...?

@mahagr mahagr added bug and removed by design labels Mar 12, 2018
@hundblue
Copy link
Author

Yes, exactly. Similarly, in my first example which I gave when I opened the issue, I was saying that /foo/bar/foo/baz will become /bar/baz instead of /bar/foo/baz.

@mahagr
Copy link
Member

mahagr commented Jun 14, 2018

Should be fixed for Grav 1.4.6

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

No branches or pull requests

3 participants