diff --git a/nevermined_sdk_py/gateway/gateway.py b/nevermined_sdk_py/gateway/gateway.py index 97e6a29..515326d 100644 --- a/nevermined_sdk_py/gateway/gateway.py +++ b/nevermined_sdk_py/gateway/gateway.py @@ -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}') diff --git a/tests/gateway/test_gateway.py b/tests/gateway/test_gateway.py index 1167cf3..00bb896 100644 --- a/tests/gateway/test_gateway.py +++ b/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"