Skip to content

Commit ba2cdd5

Browse files
committed
fix:修复有特殊符号出现多余字段
1 parent 47b7e07 commit ba2cdd5

1 file changed

Lines changed: 52 additions & 2 deletions

File tree

stream/processor_field.go

Lines changed: 52 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,32 @@ func (s *Stream) compileSimpleFieldInfo(fieldSpec string) *fieldProcessInfo {
6161
}
6262

6363
// Parse alias
64-
parts := strings.Split(fieldSpec, ":")
64+
var parts []string
65+
// Helper to split field spec considering quotes
66+
splitFieldSpec := func(spec string) []string {
67+
inQuote := false
68+
var quoteChar byte
69+
for i := 0; i < len(spec); i++ {
70+
c := spec[i]
71+
if inQuote {
72+
if c == quoteChar {
73+
inQuote = false
74+
}
75+
} else {
76+
if c == '\'' || c == '"' || c == '`' {
77+
inQuote = true
78+
quoteChar = c
79+
} else if c == ':' {
80+
// Found separator
81+
return []string{spec[:i], spec[i+1:]}
82+
}
83+
}
84+
}
85+
// No separator found outside quotes
86+
return []string{spec}
87+
}
88+
89+
parts = splitFieldSpec(fieldSpec)
6590
info.fieldName = parts[0]
6691
// Remove backticks from field name
6792
if len(info.fieldName) >= 2 && info.fieldName[0] == '`' && info.fieldName[len(info.fieldName)-1] == '`' {
@@ -398,7 +423,32 @@ func (s *Stream) processSingleFieldFallback(fieldSpec string, dataMap map[string
398423
}
399424

400425
// Handle alias
401-
parts := strings.Split(fieldSpec, ":")
426+
var parts []string
427+
// Helper to split field spec considering quotes
428+
splitFieldSpec := func(spec string) []string {
429+
inQuote := false
430+
var quoteChar byte
431+
for i := 0; i < len(spec); i++ {
432+
c := spec[i]
433+
if inQuote {
434+
if c == quoteChar {
435+
inQuote = false
436+
}
437+
} else {
438+
if c == '\'' || c == '"' || c == '`' {
439+
inQuote = true
440+
quoteChar = c
441+
} else if c == ':' {
442+
// Found separator
443+
return []string{spec[:i], spec[i+1:]}
444+
}
445+
}
446+
}
447+
// No separator found outside quotes
448+
return []string{spec}
449+
}
450+
451+
parts = splitFieldSpec(fieldSpec)
402452
fieldName := parts[0]
403453
outputName := fieldName
404454
if len(parts) > 1 {

0 commit comments

Comments
 (0)