去除文件头部的u+feff
Today, we encountered an error while trying to create some database seeds from a CSV. This CSV was originally generated by me using a Ruby script which piped the output to a file and saved as a CSV.
今天,我们在尝试从CSV创建一些数据库种子时遇到错误。 该CSV最初是由我使用Ruby脚本生成的,该脚本将输出通过管道传输到文件并另存为CSV。
The CSV was checked in to Git and had been used for awhile until we had to update some parts of it by adding a new column and fixing some values.
CSV已签入Git,并使用了一段时间,直到我们不得不通过添加新列并修复一些值来更新其中的某些部分。
While we don’t know the exact reason yet, my theory is that somehow, Excel for Mac (we are all using Macs) added some additional metadata to it even after saving the file as a CSV.
尽管我们尚不知道确切原因,但我的理论是,即使将文件另存为CSV,Excel for Mac(我们都在使用Mac)也向其中添加了一些其他元数据。
This in turn made anyone using the seed receive the following error:
反过来,这使使用种子的任何人都收到以下错误:
CSV::MalformedCSVError: Illegal quoting in line 1.
I opened the CSV file and nothing looked suspicious. My first thought was some left/right quotation marks were somehow mixed into the file instead of just the ‘normal’ double quotes: "
. But upon further investigation, there was nothing out of the ordinary. This led me