Strip BOM from start of CSV (or exclude it from Headers)
Diggory opened this issue · 1 comments
Hello,
It seems that macOS Excel puts a ByteOrderMarker at the start of exported CSV files. This is then copied into the first Header object.
e.g. I wanted to check that the user had imported a CSV file with the expected columns:
let correctMatchingHeader = ["Owner", "Major", "Minor", "UUID"]
guard csv.header == correctMatchingHeader else {
log.error("CSV Headers aren't as expected: \(csv.header) vs \(correctMatchingHeader)")
throw HBHTTPError(.badRequest)
}
gave me the error:
2023-04-09 12:44:10 🧵8744294 [🔴 ERROR] GateControl/Beacon.swift#L.265 uploadCSV(request:) CSV Headers aren't as expected: ["Owner", "Major", "Minor", "UUID"] vs ["Owner", "Major", "Minor", "UUID"]
They appear the same, but copying the error to TextMate shows that there's an invisible character in the first header (Owner), so the arrays don't match.
CSV Headers aren't as expected: ["<U+FEFF>Owner", "Major", "Minor", "UUID"] vs ["Owner", "Major", "Minor", "UUID"]
This is a BOM character at the start of the CSV file. See more here
Would it be possible to remove the character when building the 'headers'?
Thanks.