Skip to content

Commit c9fbfe8

Browse files
authored
fix: remove minimum PNG logo width check (#349)
publiccodeyml/publiccode.yml#301 clarified the logo requirements to just SHOULD be in vector format, removing the prescriptive raster fallback constraints (transparent PNG, minimum width).
1 parent 53eaa42 commit c9fbfe8

2 files changed

Lines changed: 1 addition & 37 deletions

File tree

validations.go

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,6 @@ func init() {
4444
}
4545
}
4646

47-
// Despite the spec requires at least 1000px, we temporarily release this constraint to 120px.
48-
const minLogoWidth = 120
49-
5047
func getBasicAuth(domain Domain) string {
5148
if len(domain.BasicAuth) > 0 {
5249
auth := domain.BasicAuth[rand.Intn(len(domain.BasicAuth))] //nolint:gosec,lll // G404: not security-sensitive, picks from pre-configured list
@@ -230,14 +227,9 @@ func (p *Parser) validLogo(u url.URL, network bool) (bool, error) {
230227

231228
defer f.Close()
232229

233-
image, _, err := image.DecodeConfig(f)
234-
if err != nil {
230+
if _, _, err := image.DecodeConfig(f); err != nil {
235231
return false, fmt.Errorf("%w", err)
236232
}
237-
238-
if image.Width < minLogoWidth {
239-
return false, fmt.Errorf("invalid image size of %d (min %dpx of width): %s", image.Width, minLogoWidth, netutil.DisplayURL(&u)) //nolint:err113,lll // dynamic message with image dimensions
240-
}
241233
}
242234

243235
return true, nil

validations_test.go

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
11
package publiccode
22

33
import (
4-
"image"
5-
"image/png"
64
"net/http"
75
"net/http/httptest"
86
"net/url"
9-
"os"
107
"strings"
118
"testing"
129
)
@@ -200,31 +197,6 @@ func TestValidLogoRemoteDownloadFailure(t *testing.T) {
200197
}
201198
}
202199

203-
func TestValidLogoPNGTooSmall(t *testing.T) {
204-
// Create a tiny valid PNG (1x1 pixel) which is smaller than minLogoWidth.
205-
f, err := os.CreateTemp("", "tiny-*.png")
206-
if err != nil {
207-
t.Fatalf("can't create temp file: %v", err)
208-
}
209-
defer os.Remove(f.Name())
210-
211-
// Write a minimal 1x1 PNG.
212-
png.Encode(f, image.NewRGBA(image.Rect(0, 0, 1, 1)))
213-
f.Close()
214-
215-
p, _ := NewParser(ParserConfig{DisableNetwork: true})
216-
u := url.URL{Scheme: "file", Path: f.Name()}
217-
ok, err := p.validLogo(u, false)
218-
if ok {
219-
t.Error("expected false for tiny PNG")
220-
}
221-
if err == nil {
222-
t.Error("expected error for too-small image")
223-
}
224-
if !strings.Contains(err.Error(), "invalid image size") {
225-
t.Errorf("unexpected error: %v", err)
226-
}
227-
}
228200

229201
func TestIsReachableSuccess(t *testing.T) {
230202
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {

0 commit comments

Comments
 (0)