this method attempts to mimic the same functionality on the client that the platform does on uploaded assets in order to allow the --clobber logic work correctly, since that feature is one that only exists in the client
(name string)
| 133 | // uploaded assets in order to allow the --clobber logic work correctly, since that feature is |
| 134 | // one that only exists in the client |
| 135 | func sanitizeFileName(name string) string { |
| 136 | value := text.RemoveDiacritics(name) |
| 137 | // Stripped all non-ascii characters, provide default name. |
| 138 | if strings.HasPrefix(value, ".") { |
| 139 | value = "default" + value |
| 140 | } |
| 141 | |
| 142 | // Replace special characters with the separator |
| 143 | value = regexp.MustCompile(`(?i)[^a-z0-9\-_\+@]+`).ReplaceAllLiteralString(value, ".") |
| 144 | |
| 145 | // No more than one of the separator in a row. |
| 146 | value = regexp.MustCompile(`\.{2,}`).ReplaceAllLiteralString(value, ".") |
| 147 | |
| 148 | // Remove leading/trailing separator. |
| 149 | value = strings.Trim(value, ".") |
| 150 | |
| 151 | // Just file extension left, add default name. |
| 152 | if name != value && !strings.Contains(value, ".") { |
| 153 | value = "default." + value |
| 154 | } |
| 155 | |
| 156 | return value |
| 157 | } |