IsValidSubfolderPath checks if a subfolder path is valid
(path string)
| 98 | |
| 99 | // IsValidSubfolderPath checks if a subfolder path is valid |
| 100 | func IsValidSubfolderPath(path string) bool { |
| 101 | // Empty path is valid (subfolder is optional) |
| 102 | if path == "" { |
| 103 | return true |
| 104 | } |
| 105 | |
| 106 | // Must not start with / (must be relative) |
| 107 | if strings.HasPrefix(path, "/") { |
| 108 | return false |
| 109 | } |
| 110 | |
| 111 | // Must not end with / (clean path format) |
| 112 | if strings.HasSuffix(path, "/") { |
| 113 | return false |
| 114 | } |
| 115 | |
| 116 | // Check for valid path characters (alphanumeric, dash, underscore, dot, forward slash) |
| 117 | validPathRegex := regexp.MustCompile(`^[a-zA-Z0-9\-_./]+$`) |
| 118 | if !validPathRegex.MatchString(path) { |
| 119 | return false |
| 120 | } |
| 121 | |
| 122 | // Check that path segments are valid |
| 123 | segments := strings.Split(path, "/") |
| 124 | for _, segment := range segments { |
| 125 | // Disallow empty segments ("//"), current dir ("."), and parent dir ("..") |
| 126 | if segment == "" || segment == "." || segment == ".." { |
| 127 | return false |
| 128 | } |
| 129 | } |
| 130 | |
| 131 | return true |
| 132 | } |
| 133 | |
| 134 | // IsValidRemoteURL checks if a URL is valid for remotes (stricter than packages - no localhost allowed) |
| 135 | func IsValidRemoteURL(rawURL string) bool { |
no outgoing calls
no test coverage detected
searching dependent graphs…