Skip to content

Inconsistent space encoding in query params / Encode spaces as + with bind="query-params" #14671

@JosephMarinier

Description

@JosephMarinier

Checklist

  • I have searched the existing issues for similar issues.
  • I added a very descriptive title to this issue.
  • I have provided sufficient information below to help reproduce this issue.

Summary

When a widget has bind="query-params" and the user sets a value with spaces, they are encoded as %20. If the code then sets another value in st.query_params, all spaces become encoded as +.

Reproducible Code Example

import streamlit as st

st.selectbox("Set query param `a`", options=("default", "value with spaces"), key="a", bind="query-params")

if st.button("Set query param `b`"):
    st.query_params["b"] = "value with spaces"

Steps To Reproduce

  1. Try the code above
  2. Click on the first button
  3. Notice ?a=value%20with%20spaces encodes spaces as %20.
  4. Click on the second button
  5. Notice ?a=value+with+spaces&b=value+with+spaces encodes spaces as +, including the a query param from before.

Expected Behavior

I would expect spaces to always be encoded as +, as it has always been the case for st.query_params["b"] = "value with spaces".

Current Behavior

The spaces in values from widgets that have bind="query-params" are encoded as %20.

Is this a regression?

  • Yes, this used to work in a previous version.

Debug info

  • Streamlit version: 1.56.0
  • Python version: 3.11.9
  • Operating System: macOS
  • Browser: Chrome

Additional Information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:frontendRelated to frontend aspectsfeature:query-paramsRelated to `st.query_params`priority:P3Medium prioritystatus:confirmedBug has been confirmed by the Streamlit teamtype:bugSomething isn't working as expected

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions