去除文件头部的u+feff_关于FEFF的简短故事,一个不可见的UTF-8字符破坏了我们的CSV文件

在尝试用Ruby脚本生成的CSV文件创建数据库种子时,遇到错误。问题源于Excel for Mac在保存CSV时可能添加了额外的元数据,包括u+feff,这个不可见的UTF-8字符导致Ruby的CSV解析器出错。解决方案是避免在Excel中打开和保存CSV文件,或使用OSX的命令行工具去除隐藏字符。
摘要由CSDN通过智能技术生成

去除文件头部的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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值