Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#4886] Allow text/plain for csv uploads #4940

Merged
merged 1 commit into from
Dec 18, 2024
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
10 changes: 10 additions & 0 deletions src/openforms/formio/api/validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,16 @@ def __call__(self, value: UploadedFile) -> None:
raise serializers.ValidationError(
_("The provided file is not a {file_type}.").format(file_type=f".{ext}")
)
# gh #4886
# We need to accept text/plain as a valid MIME type for CSV files.
# If the file does not strictly follow the conventions of CSV (e.g. non-standard delimiters),
# may not be considered as a valid CSV.
elif (
value.content_type == "text/csv"
and mime_type == "text/plain"
and ext == "csv"
):
return
elif mime_type == "image/heic" and value.content_type in (
"image/heic",
"image/heif",
Expand Down
1 change: 1 addition & 0 deletions src/openforms/formio/tests/files/test-csv-file.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
123
14 changes: 14 additions & 0 deletions src/openforms/formio/tests/test_validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,20 @@ def test_multiple_valid_mimetypes_in_zip_files_are_transformed(self):

validator(sample)

def test_allowed_mime_types_for_csv_files(self):
valid_types = ("text/csv", "text/plain")
csv_file = TEST_FILES / "test-csv-file.csv"
validator = validators.MimeTypeValidator()

for valid_type in valid_types:
sample = SimpleUploadedFile(
"test-csv-file.csv",
csv_file.read_bytes(),
content_type=valid_type,
)

validator(sample)

def test_validate_files_multiple_mime_types(self):
"""Assert that validation of files associated with multiple mime types works

Expand Down
Loading