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

with_suffix always reencode entire name #1467

Open
4 of 5 tasks
NTFSvolume opened this issue Feb 9, 2025 · 1 comment · May be fixed by #1468
Open
4 of 5 tasks

with_suffix always reencode entire name #1467

NTFSvolume opened this issue Feb 9, 2025 · 1 comment · May be fixed by #1468
Labels

Comments

@NTFSvolume
Copy link

Please confirm the following

  • I understand this is open source software provided for free and that I might not receive a timely response.
  • I am positive I am NOT reporting a (potential) security
    vulnerability, to the best of my knowledge. (These must be shared by
    submitting this report form instead, if
    any hesitation exists.)
  • I am willing to submit a pull request with reporoducers as xfailing test cases or even entire fix. (Assign this issue to me.)

Describe the bug

Calling with_suffix always re-encode the entire name. That's because with_suffix calls with_name under the hood, which always auto encodes

from the method's description:

suffix is encoded if needed

yarl/yarl/_url.py

Lines 1350 to 1354 in 07c1b4f

"""Return a new URL with suffix (file extension of name) replaced.
Query and fragment parts are cleaned up.
suffix is encoded if needed.

To Reproduce

from yarl import URL
url = URL("https://domain.com/video file.mp4")
print (url) # https://domain.com/video%20file.mp4
print (url.with_suffix(".avi")) # https://domain.com/video%2520file.avi

Expected behavior

Only the suffix should be encoded (if needed) instead of the entire name.

Therefore, the expected result would be https://domain.com/video%20file.avi instead of https://domain.com/video%2520file.avi

Logs/tracebacks

NA

Python Version

$ python --version
Python 3.13.2

multidict Version

$ python -m pip show multidict
Version: 6.1.0

propcache Version

$ python -m pip show propcache
Version: 0.2.1

yarl Version

$ python -m pip show yarl
Version: 1.18.3

OS

Windows 10

Additional context

No response

@NTFSvolume NTFSvolume added the bug label Feb 9, 2025
@asvetlov
Copy link
Member

asvetlov commented Feb 9, 2025

Good catch! Would you propose a fix?

@NTFSvolume NTFSvolume linked a pull request Feb 9, 2025 that will close this issue
3 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants