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
1 change: 1 addition & 0 deletions lib/galaxy/util/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2043,6 +2043,7 @@ def lowercase_alphanum_to_hex(lowercase_alphanum: str) -> str:


def to_content_disposition(target: str) -> str:
target = target.strip()
filename, ext = os.path.splitext(target)
character_limit = 255 - len(ext)
sanitized_filename = "".join(c in FILENAME_VALID_CHARS and c or "_" for c in filename)[0:character_limit] + ext
Expand Down
18 changes: 18 additions & 0 deletions test/unit/util/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,3 +202,21 @@ def test_validate_doi_fail_too_long():
def test_ready_name_for_url(input_name, expected_output):
"""Test that ready_name_for_url correctly sanitizes names for URL use."""
assert util.ready_name_for_url(input_name) == expected_output


@pytest.mark.parametrize(
"target,expected_substring",
[
("normal.txt", 'filename="normal.txt"'),
("file.gz ", 'filename="file.gz"'),
(" file.gz", 'filename="file.gz"'),
(" file.gz ", 'filename="file.gz"'),
("Galaxy102-[name].fastqsanger.gz ", 'filename="Galaxy102-[name].fastqsanger.gz"'),
],
)
def test_to_content_disposition(target, expected_substring):
result = util.to_content_disposition(target)
assert result.startswith("attachment; ")
assert expected_substring in result
# Ensure no trailing whitespace in the header value
assert result == result.strip()
Loading