Skip to content
Closed
Changes from 1 commit
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
12 changes: 10 additions & 2 deletions internal/cli/sketch/new.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ import (
"context"
"os"
"strings"

"regexp"
"fmt"
"github.com/arduino/arduino-cli/arduino/globals"
sk "github.com/arduino/arduino-cli/commands/sketch"
"github.com/arduino/arduino-cli/internal/cli/feedback"
Expand All @@ -38,7 +39,14 @@ func initNewCommand() *cobra.Command {
Long: tr("Create a new Sketch"),
Example: " " + os.Args[0] + " sketch new MultiBlinker",
Args: cobra.ExactArgs(1),
Run: func(cmd *cobra.Command, args []string) { runNewCommand(args, overwrite) },
Run: func(cmd *cobra.Command, args []string) {
re := regexp.MustCompile("^[a-zA-Z].")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This regular expression is incorrect. See the requirements in the Arduino Sketch Specification:

https://arduino.github.io/arduino-cli/dev/sketch-specification/#sketch-folders-and-files

You can see a correct regular expression (JavaScript-based) here:

https://github.com/arduino/arduino-ide/blob/2cb9d64f307c6b4f8a0d0bd652c6cac2058f090f/arduino-ide-extension/src/common/protocol/sketches-service.ts#L165

if !re.MatchString(args[0]) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are testing the entire path here. The specification must be applied only to the sketch folder name.

This is the reason the unit tests are failing. Even though they have a valid sketch folder name, the path starts with /, which is not allowed by your regex.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the quick reply, I'm working on those changes now.

fmt.Println("Error: Value can only contain alphabetic characters")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
fmt.Println("Error: Value can only contain alphabetic characters")
fmt.Println("Error: Value can only contain alphabetic characters")

The error message is incorrect. You can see an appropriate error message here:

https://github.com/arduino/arduino-ide/blob/2cb9d64f307c6b4f8a0d0bd652c6cac2058f090f/arduino-ide-extension/src/common/protocol/sketches-service.ts#L152

return
}
runNewCommand(args, overwrite)
},
}

newCommand.Flags().BoolVarP(&overwrite, "overwrite", "f", false, tr("Overwrites an existing .ino sketch."))
Expand Down