Skip to content

Commit 0b05639

Browse files
committed
fix: handle spaces in file paths in Modelfile parsing
Fixes issue #207 where Modelfile parsing would fail with 'invalid args' error when file paths contained spaces without quotes. Changes: - Modified parseStringArgs() to join multiple arguments with spaces - This handles unquoted paths like 'CONFIG example workflows/file.json' - Maintains backward compatibility with quoted paths - Updated tests to reflect new behavior - Added comprehensive test coverage for edge cases The fix allows both: - CONFIG "path with spaces/file.json" (quoted - existing behavior) - CONFIG path with spaces/file.json (unquoted - new behavior) Signed-off-by: Ricardo Aravena <[email protected]>
1 parent 3821ba8 commit 0b05639

File tree

3 files changed

+16
-7
lines changed

3 files changed

+16
-7
lines changed

pkg/modelfile/modelfile_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1308,8 +1308,8 @@ MODEL model weights.bin
13081308
CODE inference script.py
13091309
DOC README file.md
13101310
`,
1311-
expectError: true,
1312-
description: "Unquoted paths with spaces should cause parsing errors",
1311+
expectError: false,
1312+
description: "Unquoted paths with spaces are now handled correctly by joining arguments",
13131313
},
13141314
{
13151315
name: "quoted_paths_with_spaces",

pkg/modelfile/parser/args_parser.go

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,24 @@ package parser
1818

1919
import (
2020
"errors"
21+
"strings"
2122
)
2223

2324
// parseStringArgs parses the string type of args and returns a Node, for example:
2425
// "MODEL foo" args' value is "foo".
26+
// If multiple args are provided (due to unquoted spaces), they are joined with spaces.
27+
// This handles cases like: CONFIG path with spaces/file.json
2528
func parseStringArgs(args []string, start, end int) (Node, error) {
26-
if len(args) != 1 {
27-
return nil, errors.New("invalid args")
29+
if len(args) == 0 {
30+
return nil, errors.New("empty args")
2831
}
2932

30-
if args[0] == "" {
33+
// Join all arguments with spaces to handle unquoted file paths with spaces
34+
joined := strings.Join(args, " ")
35+
36+
if joined == "" {
3137
return nil, errors.New("empty args")
3238
}
3339

34-
return NewNode(args[0], start, end), nil
40+
return NewNode(joined, start, end), nil
3541
}

pkg/modelfile/parser/args_parser_test.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,11 @@ func TestParseStringArgs(t *testing.T) {
3333
{[]string{"foo"}, 1, 2, false, "foo"},
3434
{[]string{"bar"}, 3, 4, false, "bar"},
3535
{[]string{}, 5, 6, true, ""},
36-
{[]string{"foo", "bar"}, 7, 8, true, ""},
36+
{[]string{"foo", "bar"}, 7, 8, false, "foo bar"}, // Now handles multiple args by joining
3737
{[]string{""}, 9, 10, true, ""},
38+
// Additional test cases for spaces in file paths
39+
{[]string{"path", "with", "spaces/file.json"}, 11, 12, false, "path with spaces/file.json"},
40+
{[]string{"example", "workflows_Wan2.1/image_to_video_wan_480p_example.json"}, 13, 14, false, "example workflows_Wan2.1/image_to_video_wan_480p_example.json"},
3841
}
3942

4043
assert := assert.New(t)

0 commit comments

Comments
 (0)