]> Cypherpunks repositories - gostls13.git/commit
encoding/csv: avoid mangling invalid UTF-8 in Writer
authorJoe Tsai <joetsai@digital-static.net>
Wed, 7 Mar 2018 22:14:19 +0000 (14:14 -0800)
committerJoe Tsai <thebrokentoaster@gmail.com>
Thu, 8 Mar 2018 03:26:22 +0000 (03:26 +0000)
commit0add9a4dcfb4cbc0d99cd168752bd1bd641ce8e2
treeff6bfb36c2885867e0d44bd62dcb488767a2571e
parent88466e93a4d4b7503dcbf880be2cd8ad7702d632
encoding/csv: avoid mangling invalid UTF-8 in Writer

In the situation where a quoted field is necessary, avoid processing
each UTF-8 rune one-by-one, which causes mangling of invalid sequences
into utf8.RuneError, causing a loss of information.
Instead, search only for the escaped characters, handle those specially
and copy everything else in between verbatim.

This symmetrically matches the behavior of Reader.

Fixes #24298

Change-Id: I9276f64891084ce8487678f663fad711b4095dbb
Reviewed-on: https://go-review.googlesource.com/99297
Run-TryBot: Joe Tsai <thebrokentoaster@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
src/encoding/csv/writer.go
src/encoding/csv/writer_test.go