Repository navigation
Fix double base_url in get_url() for absolute URLs - #185
Merged
Merged
Conversation
bittner
force-pushed
the
fix/get-url-double-base-url
branch
from
June 3, 2026 23:13
9276c97 to
42f1452
Compare
There was a problem hiding this comment.
Pull request overview
Fixes PatchedContext.get_url() so it doesn’t incorrectly prepend base_url when resolve_url() already returns an absolute URL (e.g., to is a full URL string or get_absolute_url() returns a full URL), preventing malformed URLs like http://localhost:8000http://example.com/foo.
Changes:
- Update
PatchedContext.get_url()to detect absolute URLs (viaurllib.parse.urlparse) and return them unchanged. - Add acceptance scenarios covering full URL inputs and models whose
get_absolute_url()returns a full URL. - Add corresponding step definitions for the new acceptance scenarios.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| behave_django/environment.py | Adjusts get_url() URL-building logic to avoid double-host concatenation for absolute URLs. |
| tests/acceptance/features/context-urlhelper.feature | Adds scenarios validating absolute-URL behavior for string and model inputs. |
| tests/acceptance/steps/context-urlhelper.py | Adds step implementations to support the new acceptance scenarios. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
resolve_url() returns its input unchanged when it's already a full URL, and a model's get_absolute_url() may legitimately return one. The old implementation blindly prepended base_url, producing malformed strings like "http://localhost:8000http://example.com/foo". Refs #141.
bittner
force-pushed
the
fix/get-url-double-base-url
branch
from
June 3, 2026 23:21
42f1452 to
7953264
Compare
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.
Summary
PatchedContext.get_url()blindly prependedbase_urlto whateverresolve_url()returned. When the resolved value was already an absolute URL — either becausetowas a full URL string, or because a model'sget_absolute_url()returns one — the result was malformed:http://localhost:8000http://example.com/foo.urllib.parse.urlparseand skip the prefix when a scheme is present.Closes #141 (the
**kwargs/Pylint sub-tasks in that issue are no longer load-bearing:tois a named parameter so it cannot leak into**kwargs, and the project moved from Pylint to Ruff).Test plan
tests/acceptance/features/context-urlhelper.feature— two new scenarios cover (a) a full URL passed astoand (b) a model whoseget_absolute_url()returns a full URL.tests/manage.py behave --tags=~@failing— 31 scenarios pass, 0 fail.ruff checkandruff format --checkclean.