Fixed #36488 -- use & separator when merging query strings in RedirectView by ejucovy · Pull Request #19610 · django/django · GitHub | Latest TMZ Celebrity News & Gossip | Watch TMZ Live
Skip to content

Fixed #36488 -- use & separator when merging query strings in RedirectView #19610

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

ejucovy
Copy link

@ejucovy ejucovy commented Jun 30, 2025

Trac ticket number

ticket-36488

Branch description

  • If a RedirectView(query_string=True) has query params in its destination URL, append incoming request query params with & instead of always using ?
  • Add tests for this behavior

When merging query strings that share a param, the view will append both values (resulting in e.g. pork=spam&pork=ham) instead of replacing one with the other.

Checklist

  • This PR targets the main branch.
  • The commit message is written in past tense, mentions the ticket number, and ends with a period.
  • I have checked the "Has patch" ticket flag in the Trac system.
  • I have added or updated relevant tests.
  • I have added or updated relevant docs, including release notes if applicable.
  • I have attached screenshots in both light and dark modes for any UI changes.

…tView

* If a RedirectView(query_string=True) has query params in its destination URL,
  append incoming request query params with & instead of always using ?
* Add tests for this behavior

When merging query strings that share a param, the view will append both values
(resulting in e.g. pork=spam&pork=ham) instead of replacing one with the other.
Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

Hello! Thank you for your contribution 💪

As it's your first contribution be sure to check out the patch review checklist.

If you're fixing a ticket from Trac make sure to set the "Has patch" flag and include a link to this PR in the ticket!

If you have any design or process questions then you can ask in the Django forum.

Welcome aboard ⛵️!

Copy link
Contributor

@nessita nessita left a comment

Choose a reason for hiding this comment

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

Looks good, thank you! Added a suggestion, let me know what you think 🌟

@@ -252,7 +252,7 @@ def get_redirect_url(self, *args, **kwargs):

args = self.request.META.get("QUERY_STRING", "")
if args and self.query_string:
url = "%s?%s" % (url, args)
url = "%s%s%s" % (url, "&" if "?" in url else "?", args)
Copy link
Contributor

Choose a reason for hiding this comment

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

How about:

Suggested change
url = "%s%s%s" % (url, "&" if "?" in url else "?", args)
if urlparse(url).query:
url = f"{url}&{args}"
else:
url = f"{url}?{args}"

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.

2 participants

TMZ Celebrity News – Breaking Stories, Videos & Gossip

Looking for the latest TMZ celebrity news? You've come to the right place. From shocking Hollywood scandals to exclusive videos, TMZ delivers it all in real time.

Whether it’s a red carpet slip-up, a viral paparazzi moment, or a legal drama involving your favorite stars, TMZ news is always first to break the story. Stay in the loop with daily updates, insider tips, and jaw-dropping photos.

🎥 Watch TMZ Live

TMZ Live brings you daily celebrity news and interviews straight from the TMZ newsroom. Don’t miss a beat—watch now and see what’s trending in Hollywood.