Skip to content

Commit

Permalink
Skip http query parameters when getting the filename to download
Browse files Browse the repository at this point in the history
  • Loading branch information
r-marques committed Sep 21, 2020
1 parent 6e18be9 commit 05c3679
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
2 changes: 1 addition & 1 deletion nevermined_sdk_py/gateway/gateway.py
Expand Up @@ -403,7 +403,7 @@ def get_ecdsa_public_key(config):
@staticmethod
def _get_file_name(response):
try:
return re.match(r'attachment;filename=(.+)',
return re.match(r'attachment;filename=(.+?)($|\?)',
response.headers.get('content-disposition'))[1]
except Exception as e:
logger.warning(f'It was not possible to get the file name. {e}')
Expand Down
16 changes: 16 additions & 0 deletions tests/gateway/test_gateway.py
@@ -1,8 +1,24 @@
from nevermined_sdk_py import ConfigProvider
from nevermined_sdk_py.gateway.gateway import Gateway
from requests import Response

config = ConfigProvider.get_config()


def test_get_rsa_key():
assert Gateway.get_rsa_public_key(config)


def test_get_file_name():
response = Response()

response.headers = {"content-disposition": "attachment;filename=test.txt"}
print(response.headers.get("content-disposition"))
file_name = Gateway._get_file_name(response)
assert file_name == "test.txt"

response.headers = {
"content-disposition": "attachment;filename=test.txt?X-Amz-Algorithm=AWS4-HMAC-SHA256"
}
file_name = Gateway._get_file_name(response)
assert file_name == "test.txt"

0 comments on commit 05c3679

Please sign in to comment.