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