Skip to content
Open
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
4 changes: 2 additions & 2 deletions pkg/modelfile/modelfile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
14 changes: 10 additions & 4 deletions pkg/modelfile/parser/args_parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
11 changes: 10 additions & 1 deletion pkg/modelfile/parser/args_parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down