Skip to content

Fix CSV user import with UTF-8 BOM and improve error handling - #849

Open
rgaviras wants to merge 4 commits into
alkacon:masterfrom
rgaviras:fix/user-csv-import-master
Open

Fix CSV user import with UTF-8 BOM and improve error handling#849
rgaviras wants to merge 4 commits into
alkacon:masterfrom
rgaviras:fix/user-csv-import-master

Conversation

@rgaviras

Copy link
Copy Markdown
Contributor

This fixes CSV user imports for UTF-8 files with BOM when the first header is not quoted.

The issue occurs with valid CSV files like:

name;firstname;lastname;email;password

When the file starts with a UTF-8 BOM, the importer reads the first column as \ufeffname instead of name. It then tries to resolve a dynamic setter for that field, fails to find the
expected CmsUser#setName(String), and the import can fail with unclear behavior.

This PR:

  • removes an optional UTF-8 BOM from CSV headers and values, with both quoted and unquoted headers;
  • keeps the existing dynamic CmsUser#setXxx(String) reflection behavior;
  • keeps support for deployment-specific/custom CSV columns by storing fields without a matching setter as additional user info;
  • validates the mandatory name column and empty user names with clear errors;
  • handles incomplete rows without IndexOutOfBoundsException;
  • preserves and logs the real cause of setter invocation failures;
  • removes silent catches in the affected import flow;
  • sends notification emails only after the user has been created;
  • reports secondary failures for group, role, settings, or email operations without aborting the whole import;
  • avoids logging password values;
  • adds focused tests for BOM handling, variable columns, incomplete rows, missing name, and password fallback behavior.

Validated with:

  • ./gradlew compileJava
  • ./gradlew testSingle --tests org.opencms.ui.apps.user.TestCmsCsvImportUtils

Also manually tested on OpenCms 21.0.1 by replacing opencms.jar in a container.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant