github.com/quay/claircore@v1.5.28/pkg/path/path.go (about)

     1  package path
     2  
     3  import (
     4  	p "path"
     5  )
     6  
     7  // CanonicalizeFileName removes any leading '.', '..', './', or '../'
     8  // along with removing duplicate slashes in a file name or path
     9  func CanonicalizeFileName(path string) string {
    10  	// clean the path to remove duplicate slashes
    11  	// deeper in path
    12  	path = p.Clean(path)
    13  
    14  	// remove any occurrences of dot pathing at prefix
    15  	runes := []rune(path)
    16  	for i, r := range runes {
    17  		if r == '.' || r == '/' {
    18  			continue
    19  		}
    20  		runes = runes[i:]
    21  		break
    22  	}
    23  
    24  	return string(runes)
    25  }