Skip to content
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

Properly encode URL query parameters when building a cloning URL #5641

Conversation

jdueitt
Copy link
Contributor

@jdueitt jdueitt commented Apr 26, 2024

Closes #5640

What's Changed

Switch to utilize urllib.parse.urlencode to generate the query parameter string when cloning an object.

Screenshots

Before

Before this patch a location with the description "9th & Vine" (well anything with a special character in it) would not populate the dialog properly when cloning.
NautobotCloneIssue-0000

After

Now the clone dialog shows the description as expected.
NautobotCloneIssue-0002

TODO

  • Explanation of Change(s)
  • Added change log fragment(s) (for more information see the documentation)
  • Attached Screenshots, Payload Example
  • Unit, Integration Tests
  • Documentation Updates (when adding/changing features)
  • Example App Updates (when adding/changing features)
  • Outline Remaining Work, Constraints from Design

Test the query parameters of a Location when the Description contains
a & character.
Utilize urllib.parse to handle encoding the param dictionary.
Copy link
Contributor

@glennmatthews glennmatthews left a comment

Choose a reason for hiding this comment

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

Looks great. Can you add a changes/5640.fixed changelog fragment to the diffs?

@@ -269,7 +270,7 @@ def prepare_cloned_fields(instance):
for tag in instance.tags.all():
params.append(("tags", tag.pk))

# Concatenate parameters into a URL query string
param_string = "&".join([f"{k}={v}" for k, v in params])
Copy link
Contributor

Choose a reason for hiding this comment

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

Oof. I'm surprised this stuck around for as long as it has. Thanks for the fix!

If you'd like to go wild, there's some similarly sketchy-looking logic in nautobot.core.tables.LinkedCountColumn.render() that probably could do with a similar fix, though based on its context it's likely a lot less impactful. Not required for this PR!

@jdueitt
Copy link
Contributor Author

jdueitt commented Apr 26, 2024

I'll add that changelog fragment here shortly and update the PR.

changes/5640.fixed Outdated Show resolved Hide resolved
@glennmatthews glennmatthews mentioned this pull request Apr 29, 2024
2 tasks
@glennmatthews glennmatthews merged commit 0c1bd4e into nautobot:develop Apr 29, 2024
17 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.

Cloning objects with special characters in a clone_field
2 participants