Skip to content

Allow leading underscore in sketch filenames #2105

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

Merged
merged 1 commit into from
Mar 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
4 changes: 2 additions & 2 deletions commands/sketch/new.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ void loop() {

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

// NewSketch creates a new sketch via gRPC
func NewSketch(ctx context.Context, req *rpc.NewSketchRequest) (*rpc.NewSketchResponse, error) {
Expand Down Expand Up @@ -80,7 +80,7 @@ func validateSketchName(name string) error {
sketchNameMaxLength))}
}
if !sketchNameValidationRegex.MatchString(name) {
return &arduino.CantCreateSketchError{Cause: errors.New(tr(`invalid sketch name "%[1]s": the first character must be alphanumeric, the following ones can also contain "_", "-", and ".".`,
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 ".".`,
name))}
}
return nil
Expand Down
4 changes: 2 additions & 2 deletions commands/sketch/new_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ func Test_SketchNameWrongPattern(t *testing.T) {
invalidNames := []string{
"&",
".hello",
"_hello",
"-hello",
"hello*",
"||||||||||||||",
Expand All @@ -25,7 +24,7 @@ func Test_SketchNameWrongPattern(t *testing.T) {
SketchDir: t.TempDir(),
})

require.EqualError(t, err, fmt.Sprintf(`Can't create sketch: invalid sketch name "%s": the first character must be alphanumeric, the following ones can also contain "_", "-", and ".".`,
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 ".".`,
name))
}
}
Expand Down Expand Up @@ -66,6 +65,7 @@ func Test_SketchNameOk(t *testing.T) {
"h..ello-world",
"h..ello-world.",
"hello_world__",
"_hello_world",
string(lengthLimitName),
}
for _, name := range validNames {
Expand Down
9 changes: 6 additions & 3 deletions docs/sketch-specification.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,13 @@ The programs that run on Arduino boards are called "sketches". This term was inh

## Sketch folders and files

The sketch root folder name and code file names must start with a basic letter (`A`-`Z` or `a`-`z`) or number (`0`-`9`),
followed by basic letters, numbers, underscores (`_`), dots (`.`) and dashes (`-`). The maximum length is 63 characters.
The sketch root folder name and code file names must start with a basic letter (`A`-`Z` or `a`-`z`), number (`0`-`9`)
[<sup>1</sup>](#leading-number-note), or underscore (`_`) [<sup>2</sup>](#leading-underscore-note) followed by basic
letters, numbers, underscores, dots (`.`) and dashes (`-`). The maximum length is 63 characters.

Support for names starting with a number was added in Arduino IDE 1.8.4.
<a id="leading-number-note"></a> <sup>1</sup> Supported from Arduino IDE 1.8.4. <br />
<a id="leading-underscore-note"></a> <sup>2</sup> Supported in all versions except Arduino IDE 2.0.4/Arduino CLI
0.30.0 - 0.30.1.

### Sketch root folder

Expand Down