Skip to content

Commit 697b901

Browse files
committed
refactor: improve whitespace validation and add comprehensive test coverage
Address feedback from @gemini-code-assist[bot] review: 1. Enhanced validation in parseStringArgs(): - Use strings.TrimSpace() to reject arguments consisting solely of whitespace - Prevents creating nodes with whitespace-only paths - Maintains preservation of intentional whitespace in valid arguments 2. Added comprehensive test cases for whitespace handling: - Whitespace-only arguments (should be rejected) - Multiple empty string arguments (should be rejected) - Arguments with leading/trailing spaces (should be preserved) - Mixed whitespace scenarios This improves robustness while maintaining backward compatibility and the core functionality of handling unquoted paths with spaces.
1 parent 652d8bd commit 697b901

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

pkg/modelfile/parser/args_parser.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ func parseStringArgs(args []string, start, end int) (Node, error) {
3333
// Join all arguments with spaces to handle unquoted file paths with spaces
3434
joined := strings.Join(args, " ")
3535

36-
if joined == "" {
36+
if strings.TrimSpace(joined) == "" {
3737
return nil, errors.New("empty args")
3838
}
3939

pkg/modelfile/parser/args_parser_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,12 @@ func TestParseStringArgs(t *testing.T) {
3838
// Additional test cases for spaces in file paths
3939
{[]string{"path", "with", "spaces/file.json"}, 11, 12, false, "path with spaces/file.json"},
4040
{[]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"},
41+
// Test cases for whitespace handling
42+
{[]string{" "}, 15, 16, true, ""}, // Whitespace-only argument should be rejected
43+
{[]string{"", ""}, 17, 18, true, ""}, // Multiple empty string arguments should be rejected
44+
{[]string{" a "}, 19, 20, false, " a "}, // Arguments with leading/trailing spaces should be preserved
45+
{[]string{" ", " "}, 21, 22, true, ""}, // Multiple whitespace-only arguments should be rejected
46+
{[]string{" path ", "with", " spaces "}, 23, 24, false, " path with spaces "}, // Mixed whitespace should be preserved
4147
}
4248

4349
assert := assert.New(t)

0 commit comments

Comments
 (0)