Compare commits

1 Commits
Author SHA1 Message Date
clawbot afb5dc5d0d Refuse a fit=outside size whose output exceeds the maximum (closes #257)
check / check (push) Successful in 15m51s
fit=outside scales the source to cover the requested size, and the side
scaled past it was held to no maximum: 1x8192?fit=outside of a 3000x600
source was resized to 40960x8192 and encoded. resize now refuses such an
output with ErrOutputTooLarge before resizing, so both image routes answer
it 400 with the error a size with one side 0 already gets. The other fit
modes make the requested size or one within it. README.md and TODO.md
say so.

Model: opus-5-5
2026-10-13 10:44:45 +02:00
+14 -8
View File
@@ -19,11 +19,17 @@ import (
func TestImageProxyRefusesFitOutsideAboveMaximum(t *testing.T) { func TestImageProxyRefusesFitOutsideAboveMaximum(t *testing.T) {
t.Parallel() t.Parallel()
// The sources, by their upstream paths // The upstream paths of the sources
const (
widePath = "/wide.png"
rowPath = "/row.png"
columnPath = "/column.png"
)
sources := map[string][]byte{ sources := map[string][]byte{
"/wide.png": encodeTestPNG(t, 3000, 600), widePath: encodeTestPNG(t, 3000, 600),
"/row.png": encodeTestPNG(t, 8192, 1), rowPath: encodeTestPNG(t, 8192, 1),
"/column.png": encodeTestPNG(t, 1, 8192), columnPath: encodeTestPNG(t, 1, 8192),
} }
upstream := httptest.NewServer(http.HandlerFunc( upstream := httptest.NewServer(http.HandlerFunc(
@@ -46,10 +52,10 @@ func TestImageProxyRefusesFitOutsideAboveMaximum(t *testing.T) {
// wantWidth and wantHeight are the served image's, 0 for a refusal // wantWidth and wantHeight are the served image's, 0 for a refusal
wantWidth, wantHeight int wantWidth, wantHeight int
}{ }{
{"/wide.png", 1, 8192, 0, 0}, {widePath, 1, 8192, 0, 0},
{"/row.png", 1, 8192, 0, 0}, {rowPath, 1, 8192, 0, 0},
{"/column.png", 8192, 1, 0, 0}, {columnPath, 8192, 1, 0, 0},
{"/wide.png", 1, 1200, 6000, 1200}, {widePath, 1, 1200, 6000, 1200},
} }
for _, tt := range tests { for _, tt := range tests {