Repository navigation
fix(route): match page routes case-insensitively like React Router - #7599
Open
RaphaelFakhri wants to merge 1 commit into
Open
RaphaelFakhri wants to merge 1 commit into
RaphaelFakhri wants to merge 1 commit into
Conversation
React Router matches route paths case-insensitively by default, so /About renders the about page. The backend router matched case-sensitively, so on_load events and router.page.path fell back to the 404 page for that URL.
Contributor
[Medium impact] The PR appears safe to merge. SummaryMakes backend page routes match without regard to letter case.
Reviews (1) · Last reviewed commit: "fix(route): match page routes case-insen..." · Reviewed by Greptile |
Contributor
There was a problem hiding this comment.
1 issue found across 3 files
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="reflex/route.py">
<violation number="1" location="reflex/route.py:184">
P2: `re.IGNORECASE` enables Unicode case folding, so an ASCII route such as `/i` also matches `/İ` and `/ı` (and `/s` matches `/ſ`). Compile with ASCII-restricted case folding to avoid routing Unicode URLs that React Router treats as unmatched.</violation>
</file>
Reply with feedback, questions, or to request a fix.
View guided diff | Re-trigger cubic
| regex_pattern = f"^{regex_pattern}/?$" | ||
| return re.compile(regex_pattern) | ||
| # React Router matches route paths case-insensitively by default. | ||
| return re.compile(regex_pattern, re.IGNORECASE) |
Contributor
There was a problem hiding this comment.
P2: re.IGNORECASE enables Unicode case folding, so an ASCII route such as /i also matches /İ and /ı (and /s matches /ſ). Compile with ASCII-restricted case folding to avoid routing Unicode URLs that React Router treats as unmatched.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At reflex/route.py, line 184:
<comment>`re.IGNORECASE` enables Unicode case folding, so an ASCII route such as `/i` also matches `/İ` and `/ı` (and `/s` matches `/ſ`). Compile with ASCII-restricted case folding to avoid routing Unicode URLs that React Router treats as unmatched.</comment>
<file context>
@@ -180,7 +180,8 @@ def get_route_regex(keyworded_route: str) -> re.Pattern:
regex_pattern = f"^{regex_pattern}/?$"
- return re.compile(regex_pattern)
+ # React Router matches route paths case-insensitively by default.
+ return re.compile(regex_pattern, re.IGNORECASE)
</file context>
Suggested change
| return re.compile(regex_pattern, re.IGNORECASE) | |
| return re.compile(regex_pattern, re.IGNORECASE | re.ASCII) |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
All Submissions:
Type of change
Changes To Core Features:
Description
React Router matches route paths case-insensitively by default, so
/Aboutrenders the page registered at/about. The backend router inreflex/route.pycompiled its route regexes case-sensitively and returned no route for that URL. As a result, the page'son_loadevents did not run,router.page.pathwas/404, and the production static server answered the SPA fallback with a 404 status.This change compiles the route regexes with
re.IGNORECASE, matching the frontend. Route names are restricted to ASCII letters, digits,_and-, so the flag has no Unicode side effects.Testing
test_get_router_ignores_caseintests/units/test_route.pyfails on main (4 failed) and passes with the change.uv run pytest tests/units --ignore=tests/units/reflex_cli: 12201 passed, 67 skipped.uv run ruff check,uv run ruff format --checkanduv run pyrightare clean on the changed files.Closes #7598