Skip to content

Commit

Permalink
Restrict file name to AlNum only
Browse files Browse the repository at this point in the history
Fixes #20
  • Loading branch information
dim13 committed Jan 25, 2022
1 parent 822850f commit 12ae30e
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 7 deletions.
8 changes: 3 additions & 5 deletions migration/cleanname.go
Original file line number Diff line number Diff line change
@@ -1,21 +1,19 @@
package migration

import (
"os"
"strings"
"unicode"

"github.com/google/uuid"
)

// FileName returns sanitized filename without path delimiters
func (op *Payload_OtpParameters) FileName() string {
return strings.Map(func(r rune) rune {
switch r {
case os.PathSeparator, os.PathListSeparator:
return '_'
default:
if unicode.IsLetter(r) || unicode.IsNumber(r) {
return r
}
return '_'
}, op.Name+"_"+op.Issuer)
}

Expand Down
4 changes: 2 additions & 2 deletions migration/cleanname_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@ func TestFileName(t *testing.T) {
Name: "A/B:C.d",
Issuer: "Issuer",
},
want: "A_B_C.d_Issuer",
want: "A_B_C_d_Issuer",
},
{
op: &Payload_OtpParameters{
Name: "A/../B:C.d",
Issuer: "Issuer",
},
want: "A_.._B_C.d_Issuer",
want: "A____B_C_d_Issuer",
},
}

Expand Down

0 comments on commit 12ae30e

Please sign in to comment.