Skip to content

Commit

Permalink
feat: Escaping double dots
Browse files Browse the repository at this point in the history
Signed-off-by: Vincent Boutour <[email protected]>
  • Loading branch information
ViBiOh committed Mar 15, 2023
1 parent 1ac7d88 commit 3f9f076
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
4 changes: 3 additions & 1 deletion pkg/provider/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ var (
}
quotesChar = regexp.MustCompile(`["'` + "`" + `](?m)`)
specialChars = regexp.MustCompile(`[^a-z0-9.\-_/](?m)`)
pathEscape = regexp.MustCompile(`\.{2,}(?m)`)

BufferPool = sync.Pool{
New: func() any {
Expand Down Expand Up @@ -103,8 +104,9 @@ func SanitizeName(name string, removeSlash bool) (string, error) {
withoutSpaces := strings.Replace(withoutDiacritics, " ", "_", -1)
withoutQuotes := quotesChar.ReplaceAllString(withoutSpaces, "_")
withoutSpecials := specialChars.ReplaceAllString(withoutQuotes, "")
withoutPathEscape := pathEscape.ReplaceAllString(withoutSpecials, "_")

sanitized := withoutSpecials
sanitized := withoutPathEscape
if removeSlash {
sanitized = strings.Replace(sanitized, "/", "_", -1)
}
Expand Down
6 changes: 6 additions & 0 deletions pkg/provider/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@ func TestSanitizeName(t *testing.T) {
"path_name",
nil,
},
"should replace points": {
"path/../with/security/risk.md",
false,
"path/_/with/security/risk.md",
nil,
},
}

for intention, tc := range cases {
Expand Down

0 comments on commit 3f9f076

Please sign in to comment.