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

encoding/csv: can not Analysis word[space],word #9440

Closed
seefan opened this issue Dec 25, 2014 · 5 comments
Closed

encoding/csv: can not Analysis word[space],word #9440

seefan opened this issue Dec 25, 2014 · 5 comments

Comments

@seefan
Copy link

seefan commented Dec 25, 2014

like this "RSCP[-75dbm,-70dbm)" ,"RSCP[-80dbm,-75dbm)"
There is a space in a comma before.
like this will be ok

file:encoding/csv/reader.go
line:289

r1, err = r.readRune()
//+++
for err==nil && unicode.IsSpace(r1) {
r1, err = r.readRune()
}
//===
if err != nil || r1 == r.Comma {
break Quoted
}

@minux
Copy link
Member

minux commented Dec 25, 2014

Could you please provide a minimal runnable program example to
show the problem? Thanks.

@mikioh mikioh changed the title encoding/csv can not Analysis word[space],word encoding/csv: can not Analysis word[space],word Dec 25, 2014
@seefan
Copy link
Author

seefan commented Dec 25, 2014

package main

import (
"encoding/csv"
"log"
"os"
)

func main() {
f, err := os.Open("abc.csv")
if err != nil {
log.Println(err)
}
defer f.Close()
r := csv.NewReader(f)
r.LazyQuotes = true
r.TrimLeadingSpace = true
for {
line, err := r.Read()
if err != nil {
log.Println(err.Error())
break
}
log.Println(line)
}
}

=================abc.csv==================
"RSCP[-65dbm,-60dbm)" , "RSCP[-70dbm,-65dbm)"

@bradfitz
Copy link
Contributor

That is not a minimal example. NewReader isn't even defined, and you don't use the csv package at all.

Maybe you meant this: http://play.golang.org/p/Ez7uyrmoj2

Which yields:

record with 1 values: ["RSCP[-65dbm,-60dbm)\" , \"RSCP[-70dbm,-65dbm)"]

Whereas if you trim the whitespace around the comma, it says:

record with 2 values: ["RSCP[-65dbm,-60dbm)" "RSCP[-70dbm,-65dbm)"]

@seefan
Copy link
Author

seefan commented Dec 26, 2014

sorry, I put the code modify good, you look at.
I gave reader.go a copy is made to locate the problem, forgot to change references.

@rsc
Copy link
Contributor

rsc commented Apr 10, 2015

I believe this is working as intended. If a field is quoted it must be quoted in its entirety. Putting spaces around the comma puts spaces into the field, and it means the quote no longer appears at the end, so the field is not quoted.

See RFC 4180, bottom of page 2, for a grammar. It makes this very precise.

@rsc rsc closed this as completed Apr 10, 2015
@golang golang locked and limited conversation to collaborators Jun 25, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants