Skip to content

Commit

Permalink
delimiter supports at most 3 characters
Browse files Browse the repository at this point in the history
  • Loading branch information
lidezhu committed Dec 25, 2023
1 parent 8b42cb0 commit 55e4f24
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
4 changes: 2 additions & 2 deletions pkg/config/sink.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,14 +221,14 @@ func (c *CSVConfig) validateAndAdjust() error {
case 0:
return cerror.WrapError(cerror.ErrSinkInvalidConfig,
errors.New("csv config delimiter cannot be empty"))
case 1, 2:
case 1, 2, 3:
if strings.ContainsRune(c.Delimiter, CR) || strings.ContainsRune(c.Delimiter, LF) {
return cerror.WrapError(cerror.ErrSinkInvalidConfig,
errors.New("csv config delimiter contains line break characters"))
}
default:
return cerror.WrapError(cerror.ErrSinkInvalidConfig,
errors.New("csv config delimiter contains more than two character, note that escape "+
errors.New("csv config delimiter contains more than three characters, note that escape "+
"sequences can only be used in double quotes in toml configuration items."))
}

Expand Down
15 changes: 12 additions & 3 deletions pkg/config/sink_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,15 @@ func TestValidateAndAdjustCSVConfig(t *testing.T) {
},
wantErr: "",
},
{
name: "valid delimiter with 3 characters",
config: &CSVConfig{
Quote: "\"",
Delimiter: "|@|",
BinaryEncodingMethod: BinaryEncodingHex,
},
wantErr: "",
},
{
name: "delimiter is empty",
config: &CSVConfig{
Expand All @@ -359,12 +368,12 @@ func TestValidateAndAdjustCSVConfig(t *testing.T) {
wantErr: "csv config delimiter contains line break characters",
},
{
name: "delimiter contains more than two characters",
name: "delimiter contains more than three characters",
config: &CSVConfig{
Quote: "'",
Delimiter: "FEF",
Delimiter: "FEFA",
},
wantErr: "csv config delimiter contains more than two character, note that escape " +
wantErr: "csv config delimiter contains more than three characters, note that escape " +
"sequences can only be used in double quotes in toml configuration items.",
},
{
Expand Down

0 comments on commit 55e4f24

Please sign in to comment.