Projects

Ticket #813 (closed defect: fixed)

Opened 19 months ago

Last modified 19 months ago

/Library/Frameworks/MacRuby.framework/Versions/0.6/usr/lib/ruby/1.9.0/csv.rb:1817:in `block': Unclosed quoted field on line 1. (CSV::MalformedCSVError)

Reported by: jadarkwah@… Owned by: lsansonetti@…
Priority: blocker Milestone: MacRuby 0.7
Component: MacRuby Keywords:
Cc:

Description (last modified by martinlagardette@…) (diff)

macruby mrcsv.rb

/Library/Frameworks/MacRuby.framework/Versions/0.6/usr/lib/ruby/1.9.0/csv.rb:1817:in `block': Unclosed quoted field on line 1. (CSV::MalformedCSVError)
	from /Library/Frameworks/MacRuby.framework/Versions/0.6/usr/lib/ruby/1.9.0/csv.rb:1799:in `readline'
	from /Library/Frameworks/MacRuby.framework/Versions/0.6/usr/lib/ruby/1.9.0/csv.rb:1760:in `each'
	from /Developer/Projects/NJTransit/rail_data/scripts/./mrservice.rb:5:in `main'
	from /Developer/Projects/NJTransit/rail_data/scripts/./mrservice.rb:1:in `<main>'

The following code works with ruby, ruby1.9 and jruby but chokes on macruby.

#mrcsv.rb

require 'csv'

def main
  reader = CSV.open("mrtest.csv", "r")
  reader.each do |row|
        puts "#{row}"
  end
end

main

#mrtest.csv

1,2,"River LINE",0
2,2,"Princeton Shuttle",0
3,2,"Atlantic City Rail Line",2
4,2,"Montclair-Boonton Line",2
5,2,"Montclair-Boonton Line",2
6,2,"Hudson-Bergen Light Rail",0
7,2,"Main/Bergen County Line",2
8,2,"Port Jervis Line",2
9,2,"Morris & Essex Line",2
10,2,"Gladstone Branch",2
11,2,"Northeast Corridor",2
12,2,"North Jersey Coast Line",2
13,2,"North Jersey Coast Line",2
14,2,"Newark Light Rail",0

Change History

follow-up: ↓ 2   Changed 19 months ago by jadarkwah@…

It appears that if the lines in the csv file are quoted, then macuby acts as expected. So the following csv file works.

"1,2,River LINE,0" "2,2,Princeton Shuttle,0" "3,2,Atlantic City Rail Line,2" "4,2,Montclair-Boonton Line,2" "5,2,Montclair-Boonton Line,2" "6,2,Hudson-Bergen Light Rail,0" "7,2,Main/Bergen County Line,2" "8,2,Port Jervis Line,2" "9,2,Morris & Essex Line,2" "10,2,Gladstone Branch,2" "11,2,Northeast Corridor,2" "12,2,North Jersey Coast Line,2" "13,2,North Jersey Coast Line,2" "14,2,Newark Light Rail,0" "15,2,Pascack Valley Line,2" "16,2,Princeton Shuttle,2" "17,2,Raritan Valley Line,2" "18,2,Meadowlands Rail Line,2"

in reply to: ↑ 1   Changed 19 months ago by jadarkwah@…

Replying to jadarkwah@…: Sorry but I forgot to preview the last comment. "1,2,River LINE,0"

"2,2,Princeton Shuttle,0"

"3,2,Atlantic City Rail Line,2"

"4,2,Montclair-Boonton Line,2"

"5,2,Montclair-Boonton Line,2"

"6,2,Hudson-Bergen Light Rail,0"

"7,2,Main/Bergen County Line,2"

"8,2,Port Jervis Line,2"

"9,2,Morris & Essex Line,2"

"10,2,Gladstone Branch,2"

"11,2,Northeast Corridor,2"

"12,2,North Jersey Coast Line,2"

"13,2,North Jersey Coast Line,2"

"14,2,Newark Light Rail,0"

"15,2,Pascack Valley Line,2"

"16,2,Princeton Shuttle,2"

"17,2,Raritan Valley Line,2"

"18,2,Meadowlands Rail Line,2"

It appears that if the lines in the csv file are quoted, then macuby acts as expected. So the following csv file works. "1,2,River LINE,0" "2,2,Princeton Shuttle,0" "3,2,Atlantic City Rail Line,2" "4,2,Montclair-Boonton Line,2" "5,2,Montclair-Boonton Line,2" "6,2,Hudson-Bergen Light Rail,0" "7,2,Main/Bergen County Line,2" "8,2,Port Jervis Line,2" "9,2,Morris & Essex Line,2" "10,2,Gladstone Branch,2" "11,2,Northeast Corridor,2" "12,2,North Jersey Coast Line,2" "13,2,North Jersey Coast Line,2" "14,2,Newark Light Rail,0" "15,2,Pascack Valley Line,2" "16,2,Princeton Shuttle,2" "17,2,Raritan Valley Line,2" "18,2,Meadowlands Rail Line,2"

  Changed 19 months ago by martinlagardette@…

  • status changed from new to closed
  • resolution set to fixed
  • milestone set to MacRuby 0.7

This has been fixed in trunk already, I believe with r4114. Using the non-quoted version, I get:

$> macruby csv.rb 
["1", "2", "River LINE", "0"]
["2", "2", "Princeton Shuttle", "0"]
["3", "2", "Atlantic City Rail Line", "2"]
["4", "2", "Montclair-Boonton Line", "2"]
["5", "2", "Montclair-Boonton Line", "2"]
["6", "2", "Hudson-Bergen Light Rail", "0"]
["7", "2", "Main/Bergen County Line", "2"]
["8", "2", "Port Jervis Line", "2"]
["9", "2", "Morris & Essex Line", "2"]
["10", "2", "Gladstone Branch", "2"]
["11", "2", "Northeast Corridor", "2"]
["12", "2", "North Jersey Coast Line", "2"]
["13", "2", "North Jersey Coast Line", "2"]
["14", "2", "Newark Light Rail", "0"]

  Changed 19 months ago by martinlagardette@…

  • description modified (diff)
Note: See TracTickets for help on using tickets.