• Joe Tsai's avatar
    encoding/csv: avoid mangling invalid UTF-8 in Writer · 0add9a4d
    Joe Tsai authored
    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: 's avatarIan Lance Taylor <iant@golang.org>
    0add9a4d
writer_test.go 2.61 KB