@@ -17,6 +17,17 @@ import (
1717
1818const contentTypePlainText = "text/plain; charset=utf-8"
1919
20+ // archiveFilename returns a filename suitable for archive format detection.
21+ // Some ecosystems (e.g. composer) store artifacts with bare hash filenames
22+ // that have no extension. This adds .zip when the original has no extension
23+ // and the content is likely a zip archive.
24+ func archiveFilename (filename string ) string {
25+ if ! strings .Contains (filename , "." ) {
26+ return filename + ".zip"
27+ }
28+ return filename
29+ }
30+
2031// getStripPrefix returns the path prefix to strip for a given ecosystem.
2132// npm packages wrap content in a "package/" directory.
2233func getStripPrefix (ecosystem string ) string {
@@ -176,7 +187,7 @@ func (s *Server) browseList(w http.ResponseWriter, r *http.Request, ecosystem, n
176187
177188 // Open archive with appropriate prefix stripping
178189 stripPrefix := getStripPrefix (ecosystem )
179- archiveReader , err := archives .OpenWithPrefix (cachedArtifact .Filename , artifactReader , stripPrefix )
190+ archiveReader , err := archives .OpenWithPrefix (archiveFilename ( cachedArtifact .Filename ) , artifactReader , stripPrefix )
180191 if err != nil {
181192 s .logger .Error ("failed to open archive" , "error" , err , "filename" , cachedArtifact .Filename )
182193 http .Error (w , "failed to open archive" , http .StatusInternalServerError )
@@ -271,7 +282,7 @@ func (s *Server) browseFile(w http.ResponseWriter, r *http.Request, ecosystem, n
271282
272283 // Open archive with appropriate prefix stripping
273284 stripPrefix := getStripPrefix (ecosystem )
274- archiveReader , err := archives .OpenWithPrefix (cachedArtifact .Filename , artifactReader , stripPrefix )
285+ archiveReader , err := archives .OpenWithPrefix (archiveFilename ( cachedArtifact .Filename ) , artifactReader , stripPrefix )
275286 if err != nil {
276287 s .logger .Error ("failed to open archive" , "error" , err , "filename" , cachedArtifact .Filename )
277288 http .Error (w , "failed to open archive" , http .StatusInternalServerError )
@@ -486,15 +497,15 @@ func (s *Server) compareDiff(w http.ResponseWriter, r *http.Request, ecosystem,
486497
487498 stripPrefix := getStripPrefix (ecosystem )
488499
489- fromArchive , err := archives .OpenWithPrefix (fromArtifact .Filename , fromReader , stripPrefix )
500+ fromArchive , err := archives .OpenWithPrefix (archiveFilename ( fromArtifact .Filename ) , fromReader , stripPrefix )
490501 if err != nil {
491502 s .logger .Error ("failed to open from archive" , "error" , err )
492503 http .Error (w , "failed to open from archive" , http .StatusInternalServerError )
493504 return
494505 }
495506 defer func () { _ = fromArchive .Close () }()
496507
497- toArchive , err := archives .OpenWithPrefix (toArtifact .Filename , toReader , stripPrefix )
508+ toArchive , err := archives .OpenWithPrefix (archiveFilename ( toArtifact .Filename ) , toReader , stripPrefix )
498509 if err != nil {
499510 s .logger .Error ("failed to open to archive" , "error" , err )
500511 http .Error (w , "failed to open to archive" , http .StatusInternalServerError )
0 commit comments