Skip to content

Commit bc58cfb

Browse files
committed
🐛 Prevent collisions with plugin ID naming
1 parent b1fe9b8 commit bc58cfb

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

plugins/store-manager/main.go

+6-2
Original file line numberDiff line numberDiff line change
@@ -283,10 +283,10 @@ func uploadVersion(plugin Plugin, ids []string, token string) (string, error) {
283283
// Add the first character of the package name until the length is 15 substraction the length of the version
284284
i := 0
285285
currentLen := len(versionID.String())
286-
for i < 15-currentLen {
286+
for i < 13-currentLen {
287287
if i < len(plugin.Name) {
288288
// If the character is non-alphanumeric, skip it
289-
if !('a' <= plugin.Name[i] && plugin.Name[i] <= 'z') {
289+
if !('a' <= plugin.Name[i] && plugin.Name[i] <= 'z') && !('0' <= plugin.Name[i] && plugin.Name[i] <= '9') {
290290
versionID.WriteRune('-')
291291
} else {
292292
versionID.WriteByte(plugin.Name[i])
@@ -297,6 +297,10 @@ func uploadVersion(plugin Plugin, ids []string, token string) (string, error) {
297297
}
298298
i++
299299
}
300+
// Add the last 2 random characters to ensure no collision
301+
for i := 0; i < 2; i++ {
302+
versionID.WriteByte(alphabet[rand.IntN(len(alphabet))])
303+
}
300304

301305
if len(versionID.String()) != 15 {
302306
panic("Version ID is not 15 characters long " + versionID.String() + " " + string(len(versionID.String())))

0 commit comments

Comments
 (0)