fix: reject page routes that match the same URLs
MA
3d ago+275+275+012345678901234567890123456789-1-1-0123456789
Fixes #7833
Since #7599 the router matches routes case-insensitively, and dynamic segment names never told routes apart, so /Foo + /foo (or /Item/[id] + /item/[slug]) were both accepted and one page was unreachable without any warning.
add_pagenow raisesRouteValueErrorwhen a new route has the same match key as a registered one, kept in a map next to_unevaluated_pages. The key isreplace_brackets_with_keywords(route)with literal segments lowercased (the keywords stay as they are, so a literal__single_segment__segment is still a fixed path), and the exactindexroute keeps its own key since only it matches/.- Pages contributed by plugins go through the same check, against app pages and against other plugins, after the existing exact-match and conflict checks, so their messages still win where they already applied. Registration stays atomic.
- Message:
Route `item/[case_slug]` matches the same URLs as the already registered `Item/[case_id]`; routes are matched case-insensitively and dynamic segment names do not distinguish them. - One behaviour change to note: a same-case arg-name mismatch such as
/item/[a]+/item/[b]now fails atadd_pagewith this message, instead of later at compile with the slug-mismatch message.
Tests: rejects / accepts cases in tests/units/test_app.py and plugin-vs-app / plugin-vs-plugin cases in tests/units/compiler/test_compiler.py; 8 fail on main. pytest tests/units/test_app.py tests/units/test_route.py tests/units/compiler tests/units/plugins: 854 passed; ruff check/format clean. A bugfix news fragment is included.
All Submissions:
- Have you followed the guidelines stated in CONTRIBUTING.md file?
- Have you checked to ensure there aren't any other open Pull Requests for the desired changed?
Type of change
- Bug fix (non-breaking change which fixes an issue)