fix(map-columns): coerce uploadColumnName to string before toLowerCase#264
Open
AdarshJ173 wants to merge 1 commit into
Open
fix(map-columns): coerce uploadColumnName to string before toLowerCase#264AdarshJ173 wants to merge 1 commit into
AdarshJ173 wants to merge 1 commit into
Conversation
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)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
When a CSV file has numeric column headers (e.g.
1,2024,42), the map-columns step crashes immediately with:The root cause:
uploadColumnNameis typed asstringbut the CSV parser can producenumbervalues for purely numeric headers. BothcheckSimilarityandisSuggestedMappingcall.toLowerCase()directly on it without coercion, which throws at runtime for any non-string value.This PR wraps
uploadColumnNamewithString()before calling.toLowerCase()in both functions.String()is preferred over.toString()because it also safely handlesnullandundefinedwithout throwing.Fixes #237 — Numeric column names crash:
TypeError: uploadColumnName.toLowerCase is not a functionWhat changed
src/importer/features/map-columns/hooks/useMapColumnsTable.tsxProblem:
checkSimilaritycalleduploadColumnName.toLowerCase()directly — crashes when header is a numberChange:
String(uploadColumnName).toLowerCase()— coerces to string first, no-op for existing string inputsProblem:
isSuggestedMappingcalleduploadColumnName.toLowerCase()in the.some()comparator — same crashChange:
String(uploadColumnName).toLowerCase()— same coercion, identical fixAcceptance criteria
1,2,3or2024,2025,2026) no longer crashes the map-columns stepHow to test
1,2,3\nfoo,bar,bazName,1,Email— verify all columns rendersuggested_mappings— verify suggestions still apply for string headersNotes
String(x)is a no-op whenxis already a stringString()preferred over.toString()as it safely handlesnull/undefinedwithout throwingisMultiple/multiplecolumn logic frommainis preserved untouched — this PR targets only the two.toLowerCase()call sitesfix/numeric-column-namesbranch on upstream that applies the same.toString()fix, but that branch is behindmainand missing theisMultiplesupport added after it was created. This PR applies the fix cleanly on top of currentmain.