Skip to content

fix(organizations): Fix negative lookahead in absolute_url for org slug 'new'#112800

Draft
joshuarli wants to merge 1 commit intomasterfrom
fix/absolute-url-new-slug-regex
Draft

fix(organizations): Fix negative lookahead in absolute_url for org slug 'new'#112800
joshuarli wants to merge 1 commit intomasterfrom
fix/absolute-url-new-slug-regex

Conversation

@joshuarli
Copy link
Copy Markdown
Member

Problem

absolute_url.py strips /organizations/<slug>/ from URL paths using:

r"\/?organizations\/(?!new)[^/]+\/(.*)"

The lookahead (?!new) matches any slug that doesn't start with the string "new". This incorrectly excludes slugs like "newco" or "newly" — valid org slugs that happen to begin with "new".

Fix

-r"\/?organizations\/(?!new)[^/]+\/(.*)"
+r"\/?organizations\/(?!new\/)[^/]+\/(.*)"

Adding the trailing slash to the lookahead means only the exact path segment new/ (i.e. an org literally named "new") triggers the exclusion. Slugs starting with "new" followed by any other character are now handled correctly.

Test plan

Added a test case in tests/sentry/organizations/test_absolute_url.py covering slugs that start with "new" but are not exactly "new".

… trailing slash

The pattern (?!new) incorrectly excluded org slugs that merely start with
"new" (e.g. "newco", "newly") from /organizations/<slug>/ stripping, since
the lookahead matched on the prefix alone. Changed to (?!new/) so only the
literal path segment "new" (followed by a slash) triggers the exclusion.
@github-actions github-actions bot added the Scope: Backend Automatically applied to PRs that change backend components label Apr 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Scope: Backend Automatically applied to PRs that change backend components

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant