Pun: fix zip parsing (#24054)

This commit is contained in:
MobilettoSoft 2025-10-04 18:36:06 +02:00 • committed by GitHub
parent e31c708274
commit 290207a8c1
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -151,12 +151,18 @@ func (t *Pun) getData(day time.Time) (api.Rates, error) {
return nil, err
}
if len(zipReader.File) != 1 {
return nil, fmt.Errorf("unexpected number of files in the ZIP archive")
var tariffFile *zip.File
for _, file := range zipReader.File {
if strings.HasSuffix(file.Name, "Prezzi.xml") {
tariffFile = file
break
}
}
if tariffFile == nil {
return nil, fmt.Errorf("tariff file not found in downloaded ZIP archive")
}
zipFile := zipReader.File[0]
f, err := zipFile.Open()
f, err := tariffFile.Open()
if err != nil {
return nil, err
}