feat(django): support string-prefixed route literals and re_path()#12
Conversation
The route regexes required a quote immediately after `path(`, so routes written with a Python string-literal prefix — `path(r"...")`, f-strings, bytes — were skipped. The raw-string `r"..."` form is idiomatic in Django urls.py, so affected projects lost most of their routes. - Allow optional string-literal prefixes (`[rRbBuUfF]*`) before the quote in both `directPathRe` and `pathIncludeRe`. - Match `re_path()` in addition to `path()`. - Add a django-urls fixture and django.test.ts covering raw-string routes, re_path, include() prefixing, @api_view, and a recall guard. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
Bugbot Autofix is ON. A cloud agent has been kicked off to fix the reported issue.
Want reviews to match your repository better? Bugbot Learning can learn team-specific rules from PR activity. A team admin can enable Learning in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 46b3e63. Configure here.
|
|
||
| const directPathRe = | ||
| /path\s*\(\s*['"]([^'"]*)['"]\s*,\s*(?!include)(\w[\w.]*)/g; | ||
| /(?:path|re_path)\s*\(\s*[rRbBuUfF]*['"]([^'"]*)['"]\s*,\s*(?!include)(\w[\w.]*)/g; |
There was a problem hiding this comment.
re_path regex stored as URL
Medium Severity
directPathRe now matches re_path() with the same pipeline as path(), so the first capture is the full regex string (anchors, groups, quantifiers), not a URL segment. After include() prefixing and normalizePath, the reported endpoint path is a regex literal rather than a routable URL shape consumers expect for discovery and scanning.
Reviewed by Cursor Bugbot for commit 46b3e63. Configure here.


Problem
The Django extractor's route regexes required a quote immediately after
path(:/path\s*\(\s*['"]([^'"]*)['"]\s*,\s*(?!include)(\w[\w.]*)/gAny route written with a Python string-literal prefix —
path(r"..."), f-strings, bytes — never matched. The raw-stringr"..."form is idiomatic in Djangourls.py, so projects using it lost most of their routes during extraction.re_path()routes were also not matched at all.Fix
[rRbBuUfF]*) before the quote in bothdirectPathReandpathIncludeRe.re_path()in addition topath().Tests
scripts/fixtures/django-urls/fixture: a small Django app exercising raw-string routes, plain-quoted routes,include()prefixing,re_path(), and@api_view.src/extractors/django.test.tspinning each of those plus a recall guard. Full suite: 27/27 pass.Version bumped 0.2.1 → 0.2.2.
🤖 Generated with Claude Code
Note
Low Risk
Scoped to Django static URL parsing regexes and tests; no auth, data, or runtime API changes.
Overview
Improves Django URL discovery so idiomatic
urls.pypatterns are no longer dropped during extraction.The route-matching regexes now accept optional Python string prefixes (
r,f,b,u, etc.) before the opening quote on bothpath()/re_path()routes andinclude()mount paths, andre_path()is handled alongsidepath()for direct routes and includes.Adds a
django-urlsfixture anddjango.test.tsto lock in raw-string routes, plain quotes,include()prefixing,re_path()handlers, and@api_viewmethods, plus a recall guard on expected paths. Package version 0.2.1 → 0.2.2.Reviewed by Cursor Bugbot for commit 46b3e63. Bugbot is set up for automated code reviews on this repo. Configure here.