Skip to content

with_suffix always reencode entire name #1467

@NTFSvolume

Description

@NTFSvolume

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions