Skip to content

Commit

Permalink
Correctly sort pages if the URL suffix is empty (see contao#2784)
Browse files Browse the repository at this point in the history
Description
-----------

| Q                | A
| -----------------| ---
| Fixed issues     | Fixes contao#2775

Apparently, `substr('foo', 0, -0)` is empty 🙈

Commits
-------

502a0e0 Correctly sort pages on empty URL suffix
aa5fe3b Merge branch '4.11' into bugfix/folderurl
  • Loading branch information
aschempp authored and fritzmg committed Mar 4, 2021
1 parent 9cfd8c6 commit fdbc6b8
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 3 deletions.
4 changes: 2 additions & 2 deletions core-bundle/src/Routing/AbstractPageRouteProvider.php
Expand Up @@ -170,8 +170,8 @@ protected function compareRoutes(Route $a, Route $b, array $languages = null): i
return 1;
}

$pathA = $a instanceof PageRoute ? substr($a->getPath(), 0, -\strlen($a->getUrlSuffix())) : $a->getPath();
$pathB = $b instanceof PageRoute ? substr($b->getPath(), 0, -\strlen($b->getUrlSuffix())) : $b->getPath();
$pathA = $a instanceof PageRoute && $a->getUrlSuffix() ? substr($a->getPath(), 0, -\strlen($a->getUrlSuffix())) : $a->getPath();
$pathB = $b instanceof PageRoute && $b->getUrlSuffix() ? substr($b->getPath(), 0, -\strlen($b->getUrlSuffix())) : $b->getPath();

$countA = \count(explode('/', $pathA));
$countB = \count(explode('/', $pathB));
Expand Down
19 changes: 18 additions & 1 deletion core-bundle/tests/Fixtures/Functional/Routing/news.yml
Expand Up @@ -8,6 +8,15 @@ tl_article:
inColumn: main
published: '1'

- id: 2
pid: 8
sorting: 128
tstamp: 1539686711
title: Home
author: 1
inColumn: main
published: '1'

tl_content:
- id: 1
pid: 1
Expand All @@ -17,6 +26,14 @@ tl_content:
type: module
module: 1

- id: 2
pid: 2
ptable: tl_article
sorting: 128
tstamp: 1539686688
type: module
module: 1

tl_module:
- id: 1
pid: 1
Expand Down Expand Up @@ -62,4 +79,4 @@ tl_news_archive:
- id: 1
tstamp: 1539616536
title: Test
jumpTo: 2
jumpTo: 3
Expand Up @@ -13,7 +13,17 @@ tl_page:
layout: 1
published: '1'

# Fake page to test if page ID 3 with longer alias is sorted correctly before ID 2
- id: 2
pid: 1
sorting: 256
tstamp: 1539698035
title: Wrong Home
alias: folder/url
type: regular
published: '1'

- id: 8
pid: 1
sorting: 128
tstamp: 1539698035
Expand Down

0 comments on commit fdbc6b8

Please sign in to comment.