mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
encoding/csv: forbid certain Comma and Comment runes
The record delimiter (not configurable by user) is "\r\n" or "\n". It is insensible for the user to set Comma or Comment delimiters to be some character that conflicts with the record delimiter. Furthermore, it is insensible for Comma or Comment to be the same rune. Allowing this leaks implementation details to the user in regards to the evaluation order of which rune is checked for first. Fixes #22404 Change-Id: I31e86abc9b3a8fb4584e090477795587740970ae Reviewed-on: https://go-review.googlesource.com/72793 Reviewed-by: Ian Lance Taylor <iant@golang.org> Run-TryBot: Joe Tsai <thebrokentoaster@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org>
This commit is contained in:
parent
aedb79f092
commit
e7fed7fa35
3 changed files with 44 additions and 0 deletions
|
|
@ -9,6 +9,7 @@ import (
|
|||
"reflect"
|
||||
"strings"
|
||||
"testing"
|
||||
"unicode/utf8"
|
||||
)
|
||||
|
||||
func TestRead(t *testing.T) {
|
||||
|
|
@ -312,6 +313,35 @@ x,,,
|
|||
Input: `"""""""`,
|
||||
Output: [][]string{{`"""`}},
|
||||
LazyQuotes: true,
|
||||
}, {
|
||||
Name: "BadComma1",
|
||||
Comma: '\n',
|
||||
Error: errInvalidDelim,
|
||||
}, {
|
||||
Name: "BadComma2",
|
||||
Comma: '\r',
|
||||
Error: errInvalidDelim,
|
||||
}, {
|
||||
Name: "BadComma3",
|
||||
Comma: utf8.RuneError,
|
||||
Error: errInvalidDelim,
|
||||
}, {
|
||||
Name: "BadComment1",
|
||||
Comment: '\n',
|
||||
Error: errInvalidDelim,
|
||||
}, {
|
||||
Name: "BadComment2",
|
||||
Comment: '\r',
|
||||
Error: errInvalidDelim,
|
||||
}, {
|
||||
Name: "BadComment3",
|
||||
Comment: utf8.RuneError,
|
||||
Error: errInvalidDelim,
|
||||
}, {
|
||||
Name: "BadCommaComment",
|
||||
Comma: 'X',
|
||||
Comment: 'X',
|
||||
Error: errInvalidDelim,
|
||||
}}
|
||||
|
||||
for _, tt := range tests {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue