Code Monkey home page Code Monkey logo

Comments (5)

davich avatar davich commented on July 21, 2024 32

Right. So I should do:

csv = CSV.parse(File.read(t, encoding: 'bom|utf-8'), headers: true)

Thanks very much for your help! Sorry to raise an issue when the issue is with my understanding 👍

from csv.

matschaffer avatar matschaffer commented on July 21, 2024 7

I had to do this with a file today as well (parsing an export from 新生銀行)

CSV.foreach(file, encoding: 'bom|utf-8') - thanks for posting your solution @davich

from csv.

khiav223577 avatar khiav223577 commented on July 21, 2024 2

Right. So I should do:

csv = CSV.parse(File.read(t, encoding: 'bom|utf-8'), headers: true)

Thanks very much for your help! Sorry to raise an issue when the issue is with my understanding 👍

I have to manually remove BOM in order to test the response in my rspec.

BOM = "\xEF\xBB\xBF"
expect(CSV.parse(response.body.delete_prefix(BOM))).to eq [['abcdefg']]

It is not elegant, but maybe it is intended since it says: BOM is for opening a file not parse target string. in #23

from csv.

kou avatar kou commented on July 21, 2024

BOM is for file not string data.

I don't know why some users want to use BOM for string data.
Can you show your use case?

from csv.

matschaffer avatar matschaffer commented on July 21, 2024

Per @kou 's comment, it's a little curious that response.body would contain a BOM. But if it does, what you did seems to make sense.

I see a mention of using IO.read on https://bugs.ruby-lang.org/issues/15210 from @nobu but I'm not sure it makes sense just to remove a few characters from a string.

from csv.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.