Skip to content

fix(map-columns): coerce uploadColumnName to string before toLowerCase#264

Open
AdarshJ173 wants to merge 1 commit into
tableflowhq:mainfrom
AdarshJ173:fix/numeric-column-names-tolower
Open

fix(map-columns): coerce uploadColumnName to string before toLowerCase#264
AdarshJ173 wants to merge 1 commit into
tableflowhq:mainfrom
AdarshJ173:fix/numeric-column-names-tolower

Conversation

@AdarshJ173

Copy link
Copy Markdown

Summary

When a CSV file has numeric column headers (e.g. 1, 2024, 42), the map-columns step crashes immediately with:

TypeError: uploadColumnName.toLowerCase is not a function
    at isSuggestedMapping
    at Array.find
    at uploadColumns.reduce
    at Object.useState

The root cause: uploadColumnName is typed as string but the CSV parser can produce number values for purely numeric headers. Both checkSimilarity and isSuggestedMapping call .toLowerCase() directly on it without coercion, which throws at runtime for any non-string value.

This PR wraps uploadColumnName with String() before calling .toLowerCase() in both functions. String() is preferred over .toString() because it also safely handles null and undefined without throwing.

Fixes #237 — Numeric column names crash: TypeError: uploadColumnName.toLowerCase is not a function

What changed

src/importer/features/map-columns/hooks/useMapColumnsTable.tsx

  • Problem: checkSimilarity called uploadColumnName.toLowerCase() directly — crashes when header is a number

  • Change: String(uploadColumnName).toLowerCase() — coerces to string first, no-op for existing string inputs

  • Problem: isSuggestedMapping called uploadColumnName.toLowerCase() in the .some() comparator — same crash

  • Change: String(uploadColumnName).toLowerCase() — same coercion, identical fix

Acceptance criteria

  • Uploading a CSV with numeric column headers (e.g. 1,2,3 or 2024,2025,2026) no longer crashes the map-columns step
  • The importer renders the mapping UI correctly for numeric headers
  • String column headers behave identically to before (no regression)
  • Suggested mappings and similarity matching continue to work for string headers

How to test

  1. Create a CSV with numeric headers: 1,2,3\nfoo,bar,baz
  2. Upload it via the CSVImporter component
  3. Expected: map-columns step renders without crashing, numeric headers shown as column names
  4. Edge case: mix numeric and string headers — e.g. Name,1,Email — verify all columns render
  5. Edge case: template with suggested_mappings — verify suggestions still apply for string headers
  6. Regression: upload a normal string-header CSV — verify full flow unchanged

Notes

  • No schema changes
  • No new dependencies added
  • No server/API changes
  • No breaking changes to existing consumers — String(x) is a no-op when x is already a string
  • String() preferred over .toString() as it safely handles null/undefined without throwing
  • All isMultiple / multiple column logic from main is preserved untouched — this PR targets only the two .toLowerCase() call sites
  • Note: there is an existing fix/numeric-column-names branch on upstream that applies the same .toString() fix, but that branch is behind main and missing the isMultiple support added after it was created. This PR applies the fix cleanly on top of current main.

Closes tableflowhq#237

- Wrap uploadColumnName with String() in checkSimilarity before calling .toLowerCase()
- Wrap uploadColumnName with String() in isSuggestedMapping before calling .toLowerCase()
- Prevents TypeError crash when CSV headers are numeric (Number has no .toLowerCase)
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.

Numeric column names

1 participant