Skip to content

No validation when uploaded file doesn't match selected source type #4

@SerylLns

Description

@SerylLns

Description

When creating an import, if the user uploads a file that doesn't match the selected source type (e.g. uploads a CSV but selects XLSX, or vice versa), the import crashes during parsing instead of showing a user-friendly error on the create form.

Steps to reproduce

  1. Select a target with sources :csv, :xlsx
  2. Choose "XLSX" as source type
  3. Upload a .csv file
  4. Submit → crash in Sources::Xlsx (Creek can't parse a CSV as XLSX)

Same in reverse: select CSV, upload .xlsxCSV::MalformedCSVError

Expected behavior

The create form should validate that the uploaded file extension and/or MIME type matches the selected source type before saving the import. Display an inline error on the form like "File type does not match selected source (expected .xlsx)".

Suggested approach

Validate in the controller create action (or a before_action):

  • Check file extension against source type (.csv for csv, .xlsx for xlsx, .json for json)
  • Optionally check MIME type as a secondary check
  • Return 422 with error message rendered on the form

Note: there is already MIME type validation in ImportValidation for allowed content types, but it doesn't cross-check against the selected source type.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions