-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Search param removes values after ampersand, introduced in 2.18.2 #3106
Comments
Thank you for reporting this issue. Root CauseThe behavior you’re experiencing stems from a change in the query string parsing logic introduced in Dash 2.18.2. Specifically, the For example:
Observed Issue with
|
@T4rk1n which of these options should we pursue (or do you prefer another entirely)? |
I'd like to follow the rfc standard and expect the values to be properly encoded.
|
Hi @ezwc, Thank you for raising this issue and for providing detailed examples. Why This Issue Requires RFC ComplianceThe core problem arises from the interpretation of For example:
Under RFC-compliant parsing, this would result in: {
"param1": "something",
"bla": '',
"param2": "something2"
} If your intended behavior is to include & within a value, it should be encoded as %26:
This will correctly parse as: {
"param1": "something&bla",
"param2": "something2"
} Why RFC Compliance Is Necessary
Proposed FixBased on @T4rk1n's suggestion, I propose the following implementation for _parse_query_string, which fully complies with the RFC: from urllib.parse import parse_qs
def _parse_query_string(search):
if not search or not search.startswith("?"):
return {}
query_string = search[1:]
parsed_qs = parse_qs(query_string, keep_blank_values=True)
return {
k: v[0] if len(v) == 1 else v
for k, v in parsed_qs.items()
} Test CasesHere are some test cases with the proposed solution: query_strings = [
"?param1=something&bla¶m2=something2",
"?param1=something%26bla¶m2=something2",
"?param1=value1¶m1=value2¶m2=value3",
"?param1=¶m2=something2",
"",
]
for qs in query_strings:
print(f"Query: {qs}")
print(f"Parsed: {_parse_query_string(qs)}") Output:
@gvwilson @T4rk1n If there are no objections, I am happy to submit a PR with this fix to resolve the issue. Let me know if you have any concerns or additional feedback. 😊 |
I pass to one of my pages a search string, like:
?param1=something¶m2=something2
Accessing it uding:
def layout(**kwargs):
In 2.18.1, this works for values that included ampersand. For example:
?param1=something&bla¶m2=something2
would result in
kwargs[param1]='something&bla'
With 2.18.2 I get just:
kwargs[param1]='something'
with anything after the ampersand removed.
I would guess this is related to #2991 .
To be clear, I specifically downgraded dash to 2.18.1 and the issue went away.
The text was updated successfully, but these errors were encountered: