Skip to content

_encode_uri_path_for_uss does not skip encoded URIs #413

Description

@traeok

Describe the bug

_encode_uri_path_for_uss function does not acknowledge encoding on a URI given as input, which can result in invalid URI encoding sequences.

Expected and actual results

Expected: _encode_uri_path_for_uss should either skip encoded URIs, or at least have a note on the function clarifying that it should not be used with a URI that's already encoded.
Actual: The function encodes the URI again, causing incorrect URI encoding.

Example Python logic to detect and return early for this case:

from urllib.parse import unquote

def is_uri_encoded(uri: str) -> bool:
    """Returns True if the URI contains percent-encoded characters."""
    return uri != unquote(uri)

# Examples
print(is_uri_encoded("https://example.com%20world"))  # True
print(is_uri_encoded("https://example.com world"))  # False

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    Status
    New Issues

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions