Skip to content

Commit 478a3a4

Browse files
Exclude sketch names ending with a dot
1 parent 223d3fa commit 478a3a4

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

Diff for: commands/sketch/new.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ void loop() {
3737

3838
// sketchNameMaxLength could be part of the regex, but it's intentionally left out for clearer error reporting
3939
var sketchNameMaxLength = 63
40-
var sketchNameValidationRegex = regexp.MustCompile(`^[0-9a-zA-Z_][0-9a-zA-Z_\.-]*$`)
40+
var sketchNameValidationRegex = regexp.MustCompile(`^[0-9a-zA-Z_](?:[0-9a-zA-Z_\.-]*[0-9a-zA-Z_-]|)$`)
4141

4242
// NewSketch creates a new sketch via gRPC
4343
func NewSketch(ctx context.Context, req *rpc.NewSketchRequest) (*rpc.NewSketchResponse, error) {
@@ -80,7 +80,7 @@ func validateSketchName(name string) error {
8080
sketchNameMaxLength))}
8181
}
8282
if !sketchNameValidationRegex.MatchString(name) {
83-
return &arduino.CantCreateSketchError{Cause: errors.New(tr(`invalid sketch name "%[1]s": the first character must be alphanumeric or "_", the following ones can also contain "-" and ".".`,
83+
return &arduino.CantCreateSketchError{Cause: errors.New(tr(`invalid sketch name "%[1]s": the first character must be alphanumeric or "_", the following ones can also contain "-" and ".". The last one cannot be ".".`,
8484
name))}
8585
}
8686
return nil

Diff for: commands/sketch/new_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ func Test_SketchNameWrongPattern(t *testing.T) {
3030
".hello",
3131
"-hello",
3232
"hello*",
33+
"hello.",
3334
"||||||||||||||",
3435
",`hack[}attempt{];",
3536
}
@@ -39,7 +40,7 @@ func Test_SketchNameWrongPattern(t *testing.T) {
3940
SketchDir: t.TempDir(),
4041
})
4142

42-
require.EqualError(t, err, fmt.Sprintf(`Can't create sketch: invalid sketch name "%s": the first character must be alphanumeric or "_", the following ones can also contain "-" and ".".`,
43+
require.EqualError(t, err, fmt.Sprintf(`Can't create sketch: invalid sketch name "%s": the first character must be alphanumeric or "_", the following ones can also contain "-" and ".". The last one cannot be ".".`,
4344
name))
4445
}
4546
}
@@ -78,7 +79,6 @@ func Test_SketchNameOk(t *testing.T) {
7879
"h",
7980
"h.ello",
8081
"h..ello-world",
81-
"h..ello-world.",
8282
"hello_world__",
8383
"_hello_world",
8484
string(lengthLimitName),

0 commit comments

Comments
 (0)