Skip to content

Commit

Permalink
Error in splita/splitax when field contains a single non-string v…
Browse files Browse the repository at this point in the history
…alue (#1629)
  • Loading branch information
johnkerl authored Aug 25, 2024
1 parent 73e2117 commit f33c0b2
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 12 deletions.
15 changes: 8 additions & 7 deletions pkg/bifs/collections.go
Original file line number Diff line number Diff line change
Expand Up @@ -568,15 +568,16 @@ func BIF_splitnvx(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval {
// ----------------------------------------------------------------
// splita("3,4,5", ",") -> [3,4,5]
func BIF_splita(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval {
if !input1.IsStringOrVoid() {
return mlrval.FromNotStringError("splita", input1)
if !input1.IsLegit() {
return input1
}
input1String := input1.String()
if !input2.IsString() {
return mlrval.FromNotStringError("splita", input2)
}
fieldSeparator := input2.AcquireStringValue()

fields := lib.SplitString(input1.AcquireStringValue(), fieldSeparator)
fields := lib.SplitString(input1String, fieldSeparator)

arrayval := make([]*mlrval.Mlrval, len(fields))

Expand All @@ -592,16 +593,16 @@ func BIF_splita(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval {
// BIF_splitax splits a string to an array, without type-inference:
// e.g. splitax("3,4,5", ",") -> ["3","4","5"]
func BIF_splitax(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval {
if !input1.IsStringOrVoid() {
return mlrval.FromNotStringError("splitax", input1)
if !input1.IsLegit() {
return input1
}
input1String := input1.String()
if !input2.IsString() {
return mlrval.FromNotStringError("splitax", input2)
}
input := input1.AcquireStringValue()
fieldSeparator := input2.AcquireStringValue()

return bif_splitax_helper(input, fieldSeparator)
return bif_splitax_helper(input1String, fieldSeparator)
}

// bif_splitax_helper is split out for the benefit of BIF_splitax and
Expand Down
4 changes: 0 additions & 4 deletions test/cases/dsl-split-join/0021/expout
Original file line number Diff line number Diff line change
@@ -1,4 +0,0 @@
[3, 4, 5]
[3, 4]
[3]
[]
3 changes: 2 additions & 1 deletion test/cases/dsl-split-join/0021/mlr
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
end {
test/cases/dsl-split-join/0021/mlrend {
print splita("3,4,5", ",");
print splita("3,4", ",");
print splita("3", ",");
print splita(3, ",");
print splita("", ",");
}

0 comments on commit f33c0b2

Please sign in to comment.