- the HTML policy keeps rel on a when it holds only nofollow, sponsored and ugc tokens (D-83); any other rel value is removed - classes.MediaFileName slugs uploaded image names (lowercase, Polish letters transliterated, hyphens, at most 80 characters, image when empty) for the editor upload and POST /media/upload (D-85) - the editor corpus gains an external link with rel and a decorative image, pinned by TestEditorOutputPassesPolicy
31 lines
1.1 KiB
Go
31 lines
1.1 KiB
Go
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)
|
||
}
|
||
}
|
||
}
|