Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
6 changes: 4 additions & 2 deletions sda/internal/helper/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -458,9 +458,11 @@ func AnonymizeFilepath(fp string, username string) string {
}

func UnanonymizeFilepath(fp string, username string) string {
if strings.HasPrefix(fp, strings.Replace(username, "@", "_", 1)) {
sanitized := strings.Replace(username, "@", "_", 1)
sep := string(os.PathSeparator)
if fp == sanitized || strings.HasPrefix(fp, sanitized+sep) || fp == username || strings.HasPrefix(fp, username+sep) {
return fp
}

return filepath.Join(strings.Replace(username, "@", "_", 1), fp)
return filepath.Join(sanitized, fp)
}
14 changes: 14 additions & 0 deletions sda/internal/helper/helper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,3 +179,17 @@ func (ts *HelperTest) TestUnanonymizeFilepath_oldMessage() {
newPath := UnanonymizeFilepath(filePath, userName)
assert.Equal(ts.T(), filePath, newPath)
}

func (ts *HelperTest) TestUnanonymizeFilepath_rawUsernamePrefix() {
filePath := "test.user@demo.org/main_folder/sub_folder/file.name"
userName := "test.user@demo.org"
newPath := UnanonymizeFilepath(filePath, userName)
assert.Equal(ts.T(), filePath, newPath)
}

func (ts *HelperTest) TestUnanonymizeFilepath_bareFileNameStartingWithUsername() {
filePath := "test.user@demo.org_report.name"
userName := "test.user@demo.org"
newPath := UnanonymizeFilepath(filePath, userName)
assert.Equal(ts.T(), filepath.Join(strings.Replace(userName, "@", "_", 1), filePath), newPath)
}
Loading