starlette
starlette copied to clipboard
replace_query_params stringifies list and tuple values instead of expanding to repeated keys
Same class of problem as #3528, but in the sibling method.
from starlette.datastructures import URL
print(URL('http://x/?a=1').replace_query_params(c=['d', 'e']))
# http://x/?c=%5B%27d%27%2C+%27e%27%5D -- the repr of the list, one param
print(URL('http://x/').replace_query_params(c=('d', 'e')))
# http://x/?c=%28%27d%27%2C+%27e%27%29 -- same for tuples
Expected http://x/?c=d&c=e in both cases, matching repeated-key query encoding and the behavior of include_query_params after the fix for #3528.
The cause is the same one-liner pattern: urlencode([(str(key), str(value)) ...]) stringifies the sequence instead of emitting one pair per item. Happy to send a PR mirroring the #3528 approach if that sounds right.
Env: starlette 1.6.0 (main @ d9ed5b0 range), Python 3.14.4, Linux.
Duplicate of #3528
Thanks for reporting this and offering a fix. This is the same problem as #3528 affecting the sibling method, so I am closing this one in favor of that issue.