Skip to content

Space at end of query string is trimmed #223

Open
@Laerte

Description

@Laerte

Faced this issue while writing a spider, basically if we don't percent-encoding the space or only have one parameter the space is trimmed (if we have more parameters but the one with space is at end its also trimmed).

Find below the snippet:

from w3lib.url import safe_url_string
from urllib.parse import parse_qsl, urlparse

url = safe_url_string("https://httpbin.org/anything?keyword=A ")
assert (dict(parse_qsl(urlparse(url).query))["keyword"] == "A ") is False

url = safe_url_string("https://httpbin.org/anything?keyword=A%20")
assert (dict(parse_qsl(urlparse(url).query))["keyword"] == "A ") is True

url = safe_url_string("https://httpbin.org/anything?keyword=A &dummy=value")
assert (dict(parse_qsl(urlparse(url).query))["keyword"] == "A ") is True

url = safe_url_string("https://httpbin.org/anything?keyword=A%20&dummy=value")
assert (dict(parse_qsl(urlparse(url).query))["keyword"] == "A ") is True

url = safe_url_string("https://httpbin.org/anything?dummy=value&keyword=A ")
assert (dict(parse_qsl(urlparse(url).query))["keyword"] == "A ") is False

url = safe_url_string("https://httpbin.org/anything?dummy=value&keyword=A%20")
assert (dict(parse_qsl(urlparse(url).query))["keyword"] == "A ") is True

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions