From 55e4f242f6a46966e11afa5244877b8439c40cfb Mon Sep 17 00:00:00 2001 From: lidezhu Date: Mon, 25 Dec 2023 14:28:36 +0800 Subject: [PATCH] delimiter supports at most 3 characters --- pkg/config/sink.go | 4 ++-- pkg/config/sink_test.go | 15 ++++++++++++--- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/pkg/config/sink.go b/pkg/config/sink.go index aa755a65d8f..e959b9ebad5 100644 --- a/pkg/config/sink.go +++ b/pkg/config/sink.go @@ -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.")) } diff --git a/pkg/config/sink_test.go b/pkg/config/sink_test.go index ccb606e92da..a0378f3c4d2 100644 --- a/pkg/config/sink_test.go +++ b/pkg/config/sink_test.go @@ -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{ @@ -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.", }, {