-
-
Notifications
You must be signed in to change notification settings - Fork 385
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
[breaking] fix: validate sketch name #2051
Conversation
Codecov ReportBase: 36.50% // Head: 36.58% // Increases project coverage by
Additional details and impacted files@@ Coverage Diff @@
## master #2051 +/- ##
==========================================
+ Coverage 36.50% 36.58% +0.07%
==========================================
Files 228 228
Lines 19306 19339 +33
==========================================
+ Hits 7048 7075 +27
- Misses 11434 11436 +2
- Partials 824 828 +4
Flags with carried forward coverage won't be shown. Click here to find out more.
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. ☔ View full report at Codecov. |
fcd6cab
to
ce2cf6d
Compare
Possibly duplicate of #2049 |
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.
Code LGTM, l would wait for a review by @per1234 before merging, just to be sure we did not left out anything
6274ea5
to
bc6e64c
Compare
bc6e64c
to
35eec5e
Compare
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.
Thanks Luca!
return &arduino.CantCreateSketchError{Cause: errors.New(tr("sketch name cannot be empty"))} | ||
} | ||
if len(name) > sketchNameMaxLength { | ||
return &arduino.CantCreateSketchError{Cause: errors.New(tr("sketch name too long (%d characters). Maximum allowed length is %d", |
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.
"sketch name too long (%d characters). Maximum allowed length is %d"
This string has 2 positional parameters, you must replace %d
with %[1]d
and %[2]d
.
This would normally not be a problem, but since it's translated into another language with tr(...)
, the ordering of the parameters is not guaranteed to stay the same.
sketchNameMaxLength))} | ||
} | ||
if !sketchNameValidationRegex.MatchString(name) { | ||
return &arduino.CantCreateSketchError{Cause: errors.New(tr("invalid sketch name \"%s\". Required pattern %s", |
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 error outputs: invalid sketch name "xxx". Required pattern ^[0-9a-zA-Z][0-9a-zA-Z_\.-]*$
Not everyone is able to digest a regex, maybe a little explanation is better:
invalid sketch name "xxx": the first character must be alphanumeric, the following ones can also contain "_", "-", and ".".
Please check if the PR fulfills these requirements
See how to contribute
before creating one)
our contributing guidelines
UPGRADING.md
has been updated with a migration guide (for breaking changes)What kind of change does this PR introduce?
It alignes the validation of sketch names to the documentation
https://arduino.github.io/arduino-cli/dev/sketch-specification/#sketch-folders-and-files
Sketch creation request that don't respect the validation rules are rejected
What is the current behavior?
No validation is performed on the sketch name
What is the new behavior?
Sketch names that don't respect the required pattern, consisting in alphanumeric characters, dots, underscores and dashes, or that are longer
than 63 characters cause the request to be rejected.
Does this PR introduce a breaking change, and is titled accordingly?
Yes! Freeform sketch names that were in use before will not be compatible anymore.
Other information
Fixes #2043