Search Apps Documentation Source Content File Folder Download Copy Actions Download State String Boolean Number Struct Map Slice Pointer Function Closure Reference Nil Package Type Interface Unknown

zz_zerowidth_test.gno

1.35 Kb · 44 lines
 1package blog
 2
 3import (
 4	"strconv"
 5	"testing"
 6)
 7
 8// zwBlank holds one input per rune range chain/markdown.StripBidiAndZeroWidth
 9// removes (U+200B..U+200F, U+202A..U+202E, U+2066..U+2069, U+FEFF), plus a mix
10// with real spaces. strings.TrimSpace keeps every one of them and the render
11// strips them all, so each must be refused.
12var zwBlank = []string{
13	"\u200b\u200b\u200b", // ZWSP
14	"\u200d",             // ZWJ
15	"\u200e",             // LRM
16	"\u202e",             // RLO
17	"\u2066\u2069",       // LRI PDI
18	"\ufeff",             // BOM
19	" \u200b \u200b ",    // mixed with real spaces
20}
21
22// zwOK must stay accepted: the stripper removes the marks and leaves text.
23var zwOK = []string{"a", "a\u200bb", "  padded  "}
24
25func TestZeroWidthTitleIsRefused(cur realm, t *testing.T) {
26	reset()
27	defer reset()
28	testing.SetRealm(testing.NewUserRealm(author))
29	for i, s := range zwBlank {
30		slug := "zw" + strconv.Itoa(i)
31		if revive(func() { Set(cross(cur), slug, s, "2026-10-14", "", "body") }) == nil {
32			t.Errorf("Set accepted title %q, which the render strips to blank", s)
33		}
34	}
35	for i, s := range zwOK {
36		slug := "ok" + strconv.Itoa(i)
37		if r := revive(func() { Set(cross(cur), slug, s, "2026-10-14", "", "body") }); r != nil {
38			t.Errorf("Set refused title %q: %v", s, r)
39		}
40	}
41	if posts.Size() != len(zwOK) {
42		t.Errorf("%d post(s), want %d", posts.Size(), len(zwOK))
43	}
44}