Skip to content
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

Extend invalid characters for checking #428

Merged
merged 4 commits into from
Aug 13, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
8 changes: 4 additions & 4 deletions helpers/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -446,13 +446,13 @@ func ListFiles(config Config, prefix string) (result *s3.ListObjectsV2Output, er

// Check for invalid characters
func CheckValidChars(filename string) error {
re := regexp.MustCompile(`[\\:\*\?"<>\|\x00-\x1F\x7F]`)
dissallowedChars := re.FindAllString(filename, -1)
if dissallowedChars != nil {
re := regexp.MustCompile(`[\\<>"\|\x00-\x1F\x7F\!\*\'\(\)\;\:\@\&\=\+\$\,\?\%\#\[\]]`)
disallowedChars := re.FindAllString(filename, -1)
if disallowedChars != nil {
return fmt.Errorf(
"filepath %v contains disallowed characters: %+v",
filename,
strings.Join(dissallowedChars, ", "),
strings.Join(disallowedChars, ", "),
)
}

Expand Down
3 changes: 2 additions & 1 deletion helpers/helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,8 @@ public_key = 27be42445fd9e39c9be39e6b36a55e61e3801fc845f63781a813d3fe9977e17a

func (suite *HelperTests) TestInvalidCharacters() {
// Test that file paths with invalid characters trigger errors
for _, badc := range "\x00\x7F\x1A:*?\\" {
invalidChars := `\<>"|\!*'();:@&=+$,?#[]`
for _, badc := range invalidChars {
nanjiangshu marked this conversation as resolved.
Show resolved Hide resolved
badchar := string(badc)
testfilepath := "test" + badchar + "file"

Expand Down
Loading