Skip to content

Commit e284fcb

Browse files
authored
fix: urlencode filename for separate mod targets (#47)
* fix: urlencode filename for separate mod targets When a mod's name contains characters that should be urlencoded, any newly-uploaded versions cannot be download because of some errors regarding the URL being invalid. Make sure the returned key is urlencoded for consistency with the rest of the codebase. Signed-off-by: Angel Pons <th3fanbus@gmail.com> * fix: urlencode version in `RenameFilename` As per Mircea's comment on [#44 (comment)](#44 (comment)): I've also now noticed that RenameVersion is also not correctly escaping the filename, it's only escaping the mod's name, and not the version, which is what causes mods that use build metadata in the version (+build.1234) to fail, so that one should need a similar fix of encoding the filename. Signed-off-by: Angel Pons <th3fanbus@gmail.com> --------- Signed-off-by: Angel Pons <th3fanbus@gmail.com>
1 parent 867a34d commit e284fcb

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

storage/storage.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ func RenameVersion(ctx context.Context, modID string, name string, versionID str
276276
return false, ""
277277
}
278278

279-
return true, fmt.Sprintf("/mods/%s/%s.smod", modID, EncodeName(cleanName)+"-"+version)
279+
return true, fmt.Sprintf("/mods/%s/%s.smod", modID, EncodeName(cleanName+"-"+version))
280280
}
281281

282282
func DeleteMod(ctx context.Context, modID string, name string, versionID string) bool {
@@ -404,7 +404,8 @@ func SeparateModTarget(ctx context.Context, body []byte, modID, name, modVersion
404404

405405
zipWriter.Close()
406406

407-
key := fmt.Sprintf("/mods/%s/%s.smod", modID, cleanName+"-"+target+"-"+modVersion)
407+
filename := cleanName + "-" + target + "-" + modVersion
408+
key := fmt.Sprintf("/mods/%s/%s.smod", modID, filename)
408409

409410
_, err = storage.Put(ctx, key, bytes.NewReader(buf.Bytes()))
410411
if err != nil {
@@ -415,7 +416,8 @@ func SeparateModTarget(ctx context.Context, body []byte, modID, name, modVersion
415416
hash := sha256.New()
416417
hash.Write(buf.Bytes())
417418

418-
return true, key, hex.EncodeToString(hash.Sum(nil)), int64(buf.Len())
419+
encodedKey := fmt.Sprintf("/mods/%s/%s.smod", modID, EncodeName(filename))
420+
return true, encodedKey, hex.EncodeToString(hash.Sum(nil)), int64(buf.Len())
419421
}
420422

421423
func copyModFileToArchZip(file *zip.File, zipWriter *zip.Writer, newName string) error {

0 commit comments

Comments
 (0)