Skip to content
Merged
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: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "x2s3"
version = "1.5.0"
version = "1.5.1"
description = "RESTful web service which makes any storage system X available as an S3-compatible REST API"
readme = "README.md"
license = { file = "LICENSE" }
Expand Down
16 changes: 16 additions & 0 deletions tests/test_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -368,3 +368,19 @@ def test_virtual_prefix_continuation(app):
token = root.find('NextContinuationToken').text
assert token.startswith(VIRTUAL_PREFIX)
assert paged == all_keys


def test_list_objects_encoding_type_url(app):
# Clients such as Neuroglancer always ask for encoding-type=url, which used
# to raise a TypeError because the flag shadowed the encoding function
with TestClient(app) as client:
for bucket, prefix in [('local-files', 'tests/'),
('mounted-files', f'{VIRTUAL_PREFIX}tests/')]:
response = client.get(
f"/{bucket}?list-type=2&prefix={prefix}&delimiter=/&encoding-type=url")
assert response.status_code == 200
root = parse_xml(response.text)
assert root.find('Prefix').text == prefix
assert root.find('EncodingType').text == 'url'
assert f"{prefix}test_file.py" in [c.find('Key').text for c in root.findall('Contents')]
assert f"{prefix}java/" in [cp.find('Prefix').text for cp in root.findall('CommonPrefixes')]
2 changes: 1 addition & 1 deletion x2s3/client_aioboto.py
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ async def list_objects_v2(self,
'StartAfter': start_after
}

xml = get_list_xml(contents, common_prefixes, url_encode=False, **kwargs)
xml = get_list_xml(contents, common_prefixes, encode_values=False, **kwargs)
return Response(content=xml, media_type="application/xml")

except Exception as e:
Expand Down
7 changes: 5 additions & 2 deletions x2s3/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,12 +101,15 @@ def get_bucket_list_xml(buckets):
return elem_to_str(root)


def get_list_xml(contents, common_prefixes, url_encode=True, **kwargs):
def get_list_xml(contents, common_prefixes, encode_values=True, **kwargs):
""" Creates S3-style XML elements for the given object listing.

`encode_values` must not be named `url_encode`: that shadowed the
url_encode() function this uses to honour EncodingType=url.
"""

is_url_encode = False
if url_encode and 'EncodingType' in kwargs:
if encode_values and 'EncodingType' in kwargs:
is_url_encode = kwargs['EncodingType']=='url'

root = ET.Element("ListBucketResult", xmlns=S3_XMLNS)
Expand Down
Loading