IsLexicallyInRoot is shorthand for strings.HasPrefix(path+"/", root+"/"), but properly handling the case where path or root have a "/" suffix. NOTE: The return value only make sense if the path is already mostly cleaned (i.e., doesn't contain "..", ".", nor unneeded "/"s).
(root, path string)
| 32 | // NOTE: The return value only make sense if the path is already mostly cleaned |
| 33 | // (i.e., doesn't contain "..", ".", nor unneeded "/"s). |
| 34 | func IsLexicallyInRoot(root, path string) bool { |
| 35 | root = strings.TrimRight(root, "/") |
| 36 | path = strings.TrimRight(path, "/") |
| 37 | return strings.HasPrefix(path+"/", root+"/") |
| 38 | } |
| 39 | |
| 40 | // LexicallyCleanPath makes a path safe for use with filepath.Join. This is |
| 41 | // done by not only cleaning the path, but also (if the path is relative) |
no outgoing calls
searching dependent graphs…