Files
sm-journal-plugin/classes/media_names_test.go
Jakub Zych 391435b4bf feat: stored HTML keeps link rel and media names are slugged
- 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
2026-11-04 10:32:25 +01:00

31 lines
1.1 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
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)
}
}
}