Summary
While processing a CSV file with SmarterCSV, I encountered unexpected Duplicate Headers in CSV errors on rows that appear to be structurally valid. The same CSV parses cleanly using Ruby’s built‑in CSV library. The error seems to occur only under certain combinations of empty header columns and numeric values in the data rows.
I’m filing this issue because the behavior was surprising, difficult to trace, and seems inconsistent with how other CSV parsers handle the same input.
What I expected
I expected SmarterCSV to map each row to the header columns without raising errors, as long as:
- the CSV has a consistent number of columns
- the header row is present
- the data rows match the header column count
What actually happened
SmarterCSV raised a Duplicate Headers in CSV error for certain rows, even though:
- the CSV is well‑formed
- the number of columns matches the header row
- the numeric values in the row appear only once
- Ruby’s CSV library parses the same file without issue
The error message looks like:
Duplicate Headers in CSV: {"3"=>2}
or, depending on the row:
Duplicate Headers in CSV: {"4"=>2}
or:
Duplicate Headers in CSV: {"6"=>2}
Conditions where the error appears
Through testing, I found a pattern that reliably triggers the error:
- If the header row contains several empty columns (for example: col1,col2,,,), and
- A data row contains a numeric value within a certain range (for example: 1, 2, 3, 4, 5, 6),
then SmarterCSV raises a Duplicate Headers error even when that numeric value appears only once in the row.
The range of numbers that trigger the error seems to increase when more header columns are empty. For example:
- With 4 empty header columns, values 1–4 trigger the error
- After increasing the number of empty header columns to 6, values 1–6 trigger the error
Larger numbers (for example: 13, 455, 94133) do not trigger the error.
Additional notes
- The error occurs even when the numeric value appears only once in the row.
- The error does not occur when the numeric value is larger than the number of empty header columns.
- The same CSV parses without issues using Ruby’s built‑in CSV library.
- The behavior is consistent and reproducible across multiple files.
- Test script and sample CSV are attached.
Environment
- Ruby 3.2.x
- SmarterCSV version: 1.14.4
- macOS Sonoma 14.7.4
sample.csv
smarter_csv_test.txt
Summary
While processing a CSV file with SmarterCSV, I encountered unexpected Duplicate Headers in CSV errors on rows that appear to be structurally valid. The same CSV parses cleanly using Ruby’s built‑in CSV library. The error seems to occur only under certain combinations of empty header columns and numeric values in the data rows.
I’m filing this issue because the behavior was surprising, difficult to trace, and seems inconsistent with how other CSV parsers handle the same input.
What I expected
I expected SmarterCSV to map each row to the header columns without raising errors, as long as:
What actually happened
SmarterCSV raised a Duplicate Headers in CSV error for certain rows, even though:
The error message looks like:
Duplicate Headers in CSV: {"3"=>2}
or, depending on the row:
Duplicate Headers in CSV: {"4"=>2}
or:
Duplicate Headers in CSV: {"6"=>2}
Conditions where the error appears
Through testing, I found a pattern that reliably triggers the error:
then SmarterCSV raises a Duplicate Headers error even when that numeric value appears only once in the row.
The range of numbers that trigger the error seems to increase when more header columns are empty. For example:
Larger numbers (for example: 13, 455, 94133) do not trigger the error.
Additional notes
Environment
sample.csv
smarter_csv_test.txt