package classes import ( "strings" "testing" ) // TestMediaFileName pins the D-85 slug rule shared with the editor's J4 // form (UI-SPEC J4 backstop). func TestMediaFileName(t *testing.T) { for in, want := range map[string]string{ "Lwia Grzywa – w lesie!.JPG": "lwia-grzywa-w-lesie.jpg", "": "image", ".png": "image.png", "...": "image", "ŻÓŁĆ gęślą jaźń.webp": "zolc-gesla-jazn.webp", `C:\\Users\\x\\My Photo.jpg`: "my-photo.jpg", "../../etc/passwd.png": "passwd.png", `x" onerror="alert(1).png`: "x-onerror-alert-1.png", "name.with.dots.jpeg": "name-with-dots.jpeg", "weird.ext$": "weird-ext", "Okładka.png": "okladka.png", strings.Repeat("a", 81) + ".gif": strings.Repeat("a", 80) + ".gif", strings.Repeat("a", 79) + " b.gif": strings.Repeat("a", 79) + ".gif", } { if got := MediaFileName(in); got != want { t.Errorf("MediaFileName(%q) = %q, want %q", in, got, want) } } }