Skip to content
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

add: urlencode selector - space as plus or 20 #6621

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,5 @@ npm-debug.log

client/cypress/screenshots
client/cypress/videos

.yarnrc
3 changes: 3 additions & 0 deletions redash/settings/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -457,3 +457,6 @@ def email_server_is_configured():

# Email blocked domains, use delimiter comma to separated multiple domains
BLOCKED_DOMAINS = set_from_string(os.environ.get("REDASH_BLOCKED_DOMAINS", "qq.com"))

# Ability to urlencode spaces as %20, default is plus
URLENCODE_SPACE_AS_PLUS = parse_boolean(os.environ.get("REDASH_URLENCODE_SPACE_AS_PLUS", "true"))
12 changes: 11 additions & 1 deletion redash/utils/requests_session.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# pylint: disable=missing-module-docstring
from urllib.parse import quote, quote_plus, urlencode

# pylint: disable=unused-import
from advocate.exceptions import UnacceptableAddressException # noqa: F401

from redash import settings
Expand All @@ -8,10 +12,16 @@
import requests as requests_or_advocate


class ConfiguredSession(requests_or_advocate.Session):
class ConfiguredSession(requests_or_advocate.Session): # noqa: E501, pylint: disable=missing-class-docstring
def request(self, *args, **kwargs):
if not settings.REQUESTS_ALLOW_REDIRECTS:
kwargs.update({"allow_redirects": False})

if "params" in kwargs:
quoter = quote_plus if settings.URLENCODE_SPACE_AS_PLUS else quote

Check warning on line 21 in redash/utils/requests_session.py

View check run for this annotation

Codecov / codecov/patch

redash/utils/requests_session.py#L21

Added line #L21 was not covered by tests

kwargs["params"] = urlencode(kwargs["params"], quote_via=quoter)

Check warning on line 23 in redash/utils/requests_session.py

View check run for this annotation

Codecov / codecov/patch

redash/utils/requests_session.py#L23

Added line #L23 was not covered by tests

return super().request(*args, **kwargs)


Expand Down
Loading