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: bare " in non-quoted-field #21672

Closed
EltonSouza opened this issue Aug 28, 2017 · 3 comments
Closed

encoding/csv: bare " in non-quoted-field #21672

EltonSouza opened this issue Aug 28, 2017 · 3 comments

Comments

@EltonSouza
Copy link

Please answer these questions before submitting your issue. Thanks!

What version of Go are you using (go version)?

go version go1.8.3 linux/amd64

Does this issue reproduce with the latest release?

Yes

What operating system and processor architecture are you using (go env)?

Operating system: Linux
Architecture: amd64

What did you do?

If possible, provide a recipe for reproducing the error.
A complete runnable program is good.
A link on play.golang.org is best.
https://play.golang.org/p/8dJUQujmDQ

What did you expect to see?

[[CNPJ/CPF Data_Compra Cod_Contribuinte Cod_Cidade Cod_Empresa  Cod_Divisão  Empreendimento Bloco Cod_Unidade Cod_Parcela Cod_Ano Tipo de documento Vencimento] [	  30103201006 SP1 1200 R.0329R.94.0021 1200 VISTA VERDE 1524897 021-4 7 2017  ] [	  17002302743 SP1 1192 R.0298R.01.0011 1192 IT"S 163 1524897 011-1 7 2017   0 -1]]

What did you see instead?

line 3, column 47: bare " in non-quoted-field

problem character: "

package main

import (
	"encoding/csv"
	"fmt"
	"log"
	"strings"
)

func main() {
	in := `CNPJ/CPF,Data_Compra,Cod_Contribuinte,Cod_Cidade,Cod_Empresa ,Cod_Divisão ,Empreendimento,Bloco,Cod_Unidade,Cod_Parcela,Cod_Ano,Tipo de documento,Vencimento
	,,30103201006,SP1,1200,R.0329R.94.0021,1200 VISTA VERDE,1524897,021-4,7,2017,,
	,,17002302743,SP1,1192,R.0298R.01.0011,1192 IT"S 163,1524897,011-1,7,2017,, 0 -1`
	r := csv.NewReader(strings.NewReader(in))
	r.Comma = ','
	r.Comment = '#'

	records, err := r.ReadAll()
	if err != nil {
		log.Fatal(err)
	}

	fmt.Print(records)
}
@ericlagergren
Copy link
Contributor

ericlagergren commented Aug 28, 2017

You need to set LazyQuotes to true.

// If LazyQuotes is true, a quote may appear in an unquoted field and a
// non-doubled quote may appear in a quoted field.

@avelino
Copy link
Contributor

avelino commented Aug 28, 2017

Like the @ericlagergren said in source:
https://play.golang.org/p/t7SePY6c6I

@davecheney
Copy link
Contributor

Closing as there isn't a bug to b fixed.

@golang golang locked and limited conversation to collaborators Aug 28, 2018
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