Skip to content

Commit

Permalink
add: urlencode selector - space as plus or 20
Browse files Browse the repository at this point in the history
  • Loading branch information
veshus committed Nov 24, 2023
1 parent c99e13a commit e60d3e2
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
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

0 comments on commit e60d3e2

Please sign in to comment.