Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Loading line becomes strange when skip_lines is specified #296

Closed
rytkmt opened this issue Mar 13, 2024 · 6 comments
Closed

Loading line becomes strange when skip_lines is specified #296

rytkmt opened this issue Mar 13, 2024 · 6 comments

Comments

@rytkmt
Copy link

rytkmt commented Mar 13, 2024

If skip_lines is not specified

Ruby3.1.3 pry(main)> require 'csv'; Tempfile.open { |t| t.write(%|"\n",""\r\n|); t.rewind; CSV.open(t.path, row_sep: "\r\n") { p _1.to_a } }
=> [["\n", ""]]

If specifying skip_lines that does not affect reading

Ruby3.1.3 pry(main)> require 'csv'; Tempfile.open { |t| t.write(%|"\n",""\r\n|); t.rewind; CSV.open(t.path, skip_lines: /xxx/, row_sep: "\r\n") { p _1.to_a } }
CSV::MalformedCSVError: Any value after quoted field isn't allowed in line 1.

Probably CSV::Parser#skip_needless_lines is the cause

@kou
Copy link
Member

kou commented Mar 14, 2024

Could you try the latest csv gem?

@rytkmt
Copy link
Author

rytkmt commented Mar 14, 2024

@kou

It was the same result

Ruby3.2.3 pry(main)> require 'csv'; Tempfile.open { |t| t.write(%|"\n",""\r\n|); t.rewind; CSV.open(t.path, row_sep: "\r\n") { p _1.to_a } }
[["\n", ""]]
=> [["\n", ""]]
Ruby3.2.3 pry(main)> require 'csv'; Tempfile.open { |t| t.write(%|"\n",""\r\n|); t.rewind; CSV.open(t.path, skip_lines: /xxx/, row_sep: "\r\n") { p _1.to_a } }
CSV::MalformedCSVError: Any value after quoted field isn't allowed in line 1.
from /home/vagrant/.rbenv/versions/3.2.3/lib/ruby/3.2.0/csv/parser.rb:1067:in `parse_quotable_robust'

@kou
Copy link
Member

kou commented Mar 14, 2024

If CSV::VERSION isn't "3.2.8", you're not using the latest csv gem.

@rytkmt
Copy link
Author

rytkmt commented Mar 14, 2024

@kou
Sorry, I was wrong.

but the result was the same.

Ruby3.2.3 pry(main)> require 'csv'; Tempfile.open { |t| t.write(%|"\n",""\r\n|); t.rewind; CSV.open(t.path, row_sep: "\r\n") { p _1.to_a } }
[["\n", ""]]
=> [["\n", ""]]
Ruby3.2.3 pry(main)> require 'csv'; Tempfile.open { |t| t.write(%|"\n",""\r\n|); t.rewind; CSV.open(t.path, skip_lines: /xxx/, row_sep: "\r\n") { p _1.to_a } }
CSV::MalformedCSVError: Any value after quoted field isn't allowed in line 1.
from /home/vagrant/.rbenv/versions/3.2.3/lib/ruby/gems/3.2.0/gems/csv-3.2.8/lib/csv/parser.rb:1066:in `parse_quotable_robust'
Ruby3.2.3 pry(main)> CSV::VERSION
=> "3.2.8"

@kou kou closed this as completed in 86de331 Mar 22, 2024
@kou
Copy link
Member

kou commented Mar 22, 2024

Thanks for checking.

I've fixed this and released 3.2.9. Could you try it?

@rytkmt
Copy link
Author

rytkmt commented Mar 31, 2024

@kou Sorry for the late confirmation. I can confirm that it works properly.
Thank you for your quick response.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants