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

Community realm. Read the code first. Community realm, deployed by its author. Read the code before you interact or send coins.

zerowidth_test.gno

1.47 Kb · 46 lines
 1package threads
 2
 3import "testing"
 4
 5// Finding 325-input-validation-1 (review run 001-cd0b6a9).
 6//
 7// A validator that calls a field required must agree with the escaper its own
 8// render runs. strings.TrimSpace uses unicode.IsSpace, which does NOT include
 9// U+200B and the rest of the bidi and zero-width set, while every escaper on
10// the output side runs chain/markdown.StripBidiAndZeroWidth, which does. So a
11// value made only of those characters passes validation and renders as
12// nothing: a required field that is blank on the page.
13//
14// The cases below are the invariant, not the implementation. A value the
15// validator accepts must still be non-empty after the stripper.
16func TestValidatorsAgreeWithTheEscaper(t *testing.T) {
17	// One per class the stripper removes, so a fix that handles only
18	// U+200B does not pass.
19	blank := []string{
20		"\u200b\u200b\u200b",   // ZWSP
21		"\u200d",                // ZWJ
22		"\u200e",                // LRM
23		"\u202e",                // RLO
24		"\u2066\u2069",          // LRI PDI
25		"\ufeff",                // BOM
26		" \u200b \u200b ",        // mixed with real spaces
27	}
28	// These must stay valid: the stripper removes the marks and leaves text.
29	ok := []string{
30		"a",
31		"a\u200bb",
32		"  padded  ",
33	}
34
35	for _, s := range blank {
36		if ValidBody(s) {
37			t.Errorf("ValidBody(%q) is true, but the render strips it to empty", s)
38		}
39	}
40	for _, s := range ok {
41		if !ValidBody(s) {
42			t.Errorf("ValidBody(%q) is false, but it renders as real text", s)
43		}
44	}
45
46}