-
Notifications
You must be signed in to change notification settings - Fork 0
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
Detect invalid characters in file/directory names #116
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #116 +/- ##
==========================================
+ Coverage 59.77% 59.97% +0.19%
==========================================
Files 39 39
Lines 2603 2616 +13
==========================================
+ Hits 1556 1569 +13
Misses 920 920
Partials 127 127 ☔ View full report in Codecov by Sentry. |
935049c
to
a498615
Compare
d2a330f
to
0b76296
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 @mcantelon!
@@ -180,6 +196,13 @@ func TestValidateStructure(t *testing.T) { | |||
Failures: []string{"More than one dossier in the content directory"}, | |||
}, | |||
}, | |||
{ | |||
name: "Returns a failure when a SIP a directory name with an invalid character", |
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.
directory/file
validChars := "-_.()" | ||
|
||
// Generate string containing valid characters. | ||
validChars = appendRuneRange(validChars, 'a', 'z') | ||
validChars = appendRuneRange(validChars, 'A', 'Z') | ||
validChars = appendRuneRange(validChars, '0', '9') |
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 is nice, but I think it would be a lot clearer with a long string constant. It will also prevent from calculating it each time.
Thanks @jraddaoui ! PR updated! |
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 @mcantelon!
func validateName(name string) bool { | ||
const validChars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_.()" | ||
|
||
// Make sure only valid characters exist in name. |
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 type of comments are better above the function name:
// validateName makes sure only valid characters exist in name.
func validateName(name string) bool {
Not a big deal in this case for a small private function, but that way it documents the function and you can read it when you use it.
Added logic to validate structure to return validation errors if a file or directory's name contains characters incompatible with Archivematica.
0dd3aa8
to
d763a0f
Compare
Thanks @jraddaoui ! |
Added logic to validate structure to return validation errors if a file or directory's name contains characters incompatible with Archivematica.