-
-
Notifications
You must be signed in to change notification settings - Fork 57
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
Throw page not found if no explicit page was found but language was provided #1522
Conversation
…nd but language was provided
| @@ -150,6 +150,12 @@ public function renderPage($pageModel) | |||
| { | |||
| $objPage = $objNewPage; | |||
| } | |||
|
|
|||
| // Throw an exception if language was provided but no page was matched | |||
| elseif (isset($lang) && $lang) | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be replaced with !empty($_GET['lang']).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You sure? A few lines above you treat the \Input::get('language') as the source of truth for language: https://github.com/qzminski/contao-core-bundle/blob/b42099f8575999984b7838dda0a242aaa9462015/src/Resources/contao/controllers/FrontendIndex.php#L137
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Your code will end in an variable $lang might not have been defined warning, which is why you had to add the isset() check. Using elseif (!empty($_GET['lang'])) will solve both.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed in c035f92.
|
I just tried to reproduce this but it only worked when I did not set a language fallback. Did you happen to forget to set the language fallback? |
|
I just tried to reproduce again on demo.contao.org and it's reproducible exactly as described. And yes, fallbacks are properly enabled. |
|
Thank you @Toflar, that helped me reproduce it. However, I think the fix is wrong. It should be: --- a/src/Resources/contao/controllers/FrontendIndex.php
+++ b/src/Resources/contao/controllers/FrontendIndex.php
@@ -128,6 +128,12 @@ class FrontendIndex extends Frontend
$arrLangs = $arrPages['*'] ?: array(); // empty domain
}
+ // Throw an exception if there are no results (see #1522)
+ if (empty($arrLangs))
+ {
+ throw new PageNotFoundException('Page not found: ' . \Environment::get('uri'));
+ }
+
// Use the first result (see #4872)
if (!\Config::get('addLanguageToUrl'))
{Because in this special case, there are no entries in |
|
A diff or PR would greatly help me to review this 😄 |
|
I'm not getting diffs most of the time, either, so just copy the three lines and paste them. 😄 |
|
I have made you a diff anyways. 😄 |
|
I'm fine with the changes if they fix the issue on demo.contao.org :) |
|
Fixed in 3ea4cd3 then. |
|
I have to re-open this one, as your code in 3ea4cd3 doesn't fix this. See my little debugging info down there. The error comes up when I try to access the As you can see there are several root pages found with the given alias, but none of them has a matching language (in this case |
|
Could you give me access to the installation so I can debug this myself? |
|
@Toflar your call here. |
|
Ok, I was able to reproduce this now. 👍 @qzminski Why did you add |
|
Be aware that there is a behavioral difference between |
|
@leofeyer good question. I think I have added |
|
Fixed in contao/contao@04aa041. |
This is rather an edge case issue but still a problem, especially if you configure the site structure in a extraordinary way. Both Contao 4.4 and 4.5 are affected.
Steps to reproduce on demo contao.org. Have three published website roots:
Now if you open the URL https://demo.contao.org/de/en.html Contao will find two website root points: EN1 and EN2. In the class
Contao\FrontendIndexat line 96 the script will try to determine which page to use. Unfortunately both pages have the English language whereas we specified thede/in the URL. Thus none of the statements on lines 130-146 will be executed and$objPagewill remain unaltered. This will lead to theLogicExceptionon line 162.According to me, this is wrong because if there is no single page or multiple pages matching the provided language, then you should definitely throw the page not found exception. The ambiguous pages logic exception makes sense if there are multiple pages that actually match the language.
https://github.com/contao/core-bundle/blob/master/src/Resources/contao/controllers/FrontendIndex.php#L90
/cc @Toflar