Skip to content

feat(django): support string-prefixed route literals and re_path()#12

Merged
kylejryan merged 2 commits into
mainfrom
feat/django-string-prefixed-route-literals
Jun 18, 2026
Merged

feat(django): support string-prefixed route literals and re_path()#12
kylejryan merged 2 commits into
mainfrom
feat/django-string-prefixed-route-literals

Conversation

@kylejryan

@kylejryan kylejryan commented Jun 18, 2026

Copy link
Copy Markdown
Collaborator

Problem

The Django extractor's route regexes required a quote immediately after path(:

/path\s*\(\s*['"]([^'"]*)['"]\s*,\s*(?!include)(\w[\w.]*)/g

Any route written with a Python string-literal prefix — path(r"..."), f-strings, bytes — never matched. The raw-string r"..." form is idiomatic in Django urls.py, so projects using it lost most of their routes during extraction. re_path() routes were also not matched at all.

Fix

  • Allow optional Python string-literal prefixes ([rRbBuUfF]*) before the quote in both directPathRe and pathIncludeRe.
  • Match re_path() in addition to path().

Tests

  • New scripts/fixtures/django-urls/ fixture: a small Django app exercising raw-string routes, plain-quoted routes, include() prefixing, re_path(), and @api_view.
  • New src/extractors/django.test.ts pinning 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.py patterns 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 both path()/re_path() routes and include() mount paths, and re_path() is handled alongside path() for direct routes and includes.

Adds a django-urls fixture and django.test.ts to lock in raw-string routes, plain quotes, include() prefixing, re_path() handlers, and @api_view methods, 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.

kylejryan and others added 2 commits June 17, 2026 21:06
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>

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

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.

Comment thread src/extractors/django.ts

const directPathRe =
/path\s*\(\s*['"]([^'"]*)['"]\s*,\s*(?!include)(\w[\w.]*)/g;
/(?:path|re_path)\s*\(\s*[rRbBuUfF]*['"]([^'"]*)['"]\s*,\s*(?!include)(\w[\w.]*)/g;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 46b3e63. Configure here.

@kylejryan kylejryan merged commit 083ee07 into main Jun 18, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant