Skip to content

Commit e8c45cb

Browse files
Exclude sketch names ending with a dot
1 parent 82e6f5d commit e8c45cb

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

Diff for: commands/sketch/new.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import (
1919
"context"
2020
"errors"
2121
"regexp"
22+
"strings"
2223

2324
"github.com/arduino/arduino-cli/arduino"
2425
"github.com/arduino/arduino-cli/arduino/globals"
@@ -79,8 +80,8 @@ func validateSketchName(name string) error {
7980
len(name),
8081
sketchNameMaxLength))}
8182
}
82-
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+
if !sketchNameValidationRegex.MatchString(name) || strings.HasSuffix(name, ".") {
84+
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 ".".`,
8485
name))}
8586
}
8687
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)