Skip to content Search Apps Documentation Source Content Run Reset Eval Playground File Folder Download Copy Actions State String Boolean Number Struct Map Slice Pointer Function Closure Reference Nil Package Type Interface Unknown

zz_zerowidth_test.gno

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