-
-
Notifications
You must be signed in to change notification settings - Fork 398
Added regex based input validation when creating a new sketch #2049
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -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" | ||||||
|
@@ -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].") | ||||||
if !re.MatchString(args[0]) { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe 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") | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
The error message is incorrect. You can see an appropriate error message here: |
||||||
return | ||||||
} | ||||||
runNewCommand(args, overwrite) | ||||||
}, | ||||||
} | ||||||
|
||||||
newCommand.Flags().BoolVarP(&overwrite, "overwrite", "f", false, tr("Overwrites an existing .ino sketch.")) | ||||||
|
There was a problem hiding this comment.
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