You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When I build a HttpUrl from parts of another HttpUrl (using the HttpUrl.build() method), I frequently stumble across the fact that the parameter for path I should hand to HttpUrl.build() is not the same as the output of existingHttpUrl.path. The .path attribute includes the leading /, whereas the parameter to HttpUrl.build() does not expect it and fills it in automatically.
I'd expect this to be the same. Is this a bug or an expected behaviour?
Example Code
# Minimal, reprocucible examplefrompydanticimportHttpUrlpath="foo"url=HttpUrl.build(
scheme="https",
host="test.dev",
path=path
)
asserturl.path==path# assert "/foo" == "foo"# Problematic use case: Adding username and password to a given input urlfrompydanticimportHttpUrlfromosimportenviron# user gives any input urlh1=HttpUrl("https://test.dev/foo")
defaddCredsToUrl(h: HttpUrl) ->HttpUrl:
"""Add authentication credentials to given url"""returnHttpUrl.build(
scheme=h.scheme,
host=h.host,
path=h.path,
username="John.Doe",
password="y0urV3ryS€cRetAP!kEy",
)
addCredsToUrl(h1) # <--- this will include two // after the host part
Initial Checks
Description
When I build a
HttpUrl
from parts of anotherHttpUrl
(using theHttpUrl.build()
method), I frequently stumble across the fact that the parameter forpath
I should hand to HttpUrl.build() is not the same as the output ofexistingHttpUrl.path
. The.path
attribute includes the leading/
, whereas the parameter toHttpUrl.build()
does not expect it and fills it in automatically.I'd expect this to be the same. Is this a bug or an expected behaviour?
Example Code
Python, Pydantic & OS Version
The text was updated successfully, but these errors were encountered: