Skip to content

Commit

Permalink
Merge pull request #4940 from open-formulieren/fix/4886-windows-users…
Browse files Browse the repository at this point in the history
…-cannot-upload-csv-files

[#4886] Allow `text/plain` for csv uploads
  • Loading branch information
vaszig authored Dec 18, 2024
2 parents 25c4d56 + 57fabe8 commit f8095b4
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
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

0 comments on commit f8095b4

Please sign in to comment.