Fixes mishandling of an edge condition in the {{Split()}} subject mapping function

This commit is contained in:
jnmoyne
2022-09-09 12:42:03 -07:00
parent 925f57ccc2
commit a1f90b8776
2 changed files with 2 additions and 1 deletions

View File

@@ -4581,7 +4581,7 @@ func (tr *transform) transform(tokens []string) (string, error) {
if split != _EMPTY_ {
b.WriteString(split)
}
if j < len(splits)-1 && splits[j+1] != _EMPTY_ && j != 0 {
if j < len(splits)-1 && splits[j+1] != _EMPTY_ && !(j == 0 && split == _EMPTY_) {
b.WriteString(tsep)
}
}

View File

@@ -3335,6 +3335,7 @@ func TestSubjectTransforms(t *testing.T) {
shouldMatch("*", "{{SliceFromLeft(1,3)}}", "1234567890", "123.456.789.0")
shouldMatch("*", "{{SliceFromRight(1,3)}}", "1234567890", "1.234.567.890")
shouldMatch("*", "{{split(1,-)}}", "-abc-def--ghi-", "abc.def.ghi")
shouldMatch("*", "{{split(1,-)}}", "abc-def--ghi-", "abc.def.ghi")
shouldMatch("*.*", "{{split(2,-)}}.{{splitfromleft(1,2)}}", "foo.-abc-def--ghij-", "abc.def.ghij.fo.o") // combo + checks split for multiple instance of deliminator and deliminator being at the start or end
}