diff --git a/pkg/modelfile/modelfile_test.go b/pkg/modelfile/modelfile_test.go index 1c4fefb3..1dd301b2 100644 --- a/pkg/modelfile/modelfile_test.go +++ b/pkg/modelfile/modelfile_test.go @@ -1308,8 +1308,8 @@ MODEL model weights.bin CODE inference script.py DOC README file.md `, - expectError: true, - description: "Unquoted paths with spaces should cause parsing errors", + expectError: false, + description: "Unquoted paths with spaces are now handled correctly by joining arguments", }, { name: "quoted_paths_with_spaces", diff --git a/pkg/modelfile/parser/args_parser.go b/pkg/modelfile/parser/args_parser.go index 5f871f22..4c93c289 100644 --- a/pkg/modelfile/parser/args_parser.go +++ b/pkg/modelfile/parser/args_parser.go @@ -18,18 +18,24 @@ package parser import ( "errors" + "strings" ) // parseStringArgs parses the string type of args and returns a Node, for example: // "MODEL foo" args' value is "foo". +// If multiple args are provided (due to unquoted spaces), they are joined with spaces. +// This handles cases like: CONFIG path with spaces/file.json func parseStringArgs(args []string, start, end int) (Node, error) { - if len(args) != 1 { - return nil, errors.New("invalid args") + if len(args) == 0 { + return nil, errors.New("empty args") } - if args[0] == "" { + // Join all arguments with spaces to handle unquoted file paths with spaces + joined := strings.Join(args, " ") + + if strings.TrimSpace(joined) == "" { return nil, errors.New("empty args") } - return NewNode(args[0], start, end), nil + return NewNode(joined, start, end), nil } diff --git a/pkg/modelfile/parser/args_parser_test.go b/pkg/modelfile/parser/args_parser_test.go index 6cfe112a..72cbe182 100644 --- a/pkg/modelfile/parser/args_parser_test.go +++ b/pkg/modelfile/parser/args_parser_test.go @@ -33,8 +33,17 @@ func TestParseStringArgs(t *testing.T) { {[]string{"foo"}, 1, 2, false, "foo"}, {[]string{"bar"}, 3, 4, false, "bar"}, {[]string{}, 5, 6, true, ""}, - {[]string{"foo", "bar"}, 7, 8, true, ""}, + {[]string{"foo", "bar"}, 7, 8, false, "foo bar"}, // Now handles multiple args by joining {[]string{""}, 9, 10, true, ""}, + // Additional test cases for spaces in file paths + {[]string{"path", "with", "spaces/file.json"}, 11, 12, false, "path with spaces/file.json"}, + {[]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"}, + // Test cases for whitespace handling + {[]string{" "}, 15, 16, true, ""}, // Whitespace-only argument should be rejected + {[]string{"", ""}, 17, 18, true, ""}, // Multiple empty string arguments should be rejected + {[]string{" a "}, 19, 20, false, " a "}, // Arguments with leading/trailing spaces should be preserved + {[]string{" ", " "}, 21, 22, true, ""}, // Multiple whitespace-only arguments should be rejected + {[]string{" path ", "with", " spaces "}, 23, 24, false, " path with spaces "}, // Mixed whitespace should be preserved } assert := assert.New(t)