Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error in splita/splitax when field contains a single non-string value #1629

Merged
merged 1 commit into from
Aug 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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("", ",");
}
Loading