zerowidth_test.gno
1.47 Kb · 46 lines
1package vouch
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 ValidReason(s) {
37 t.Errorf("ValidReason(%q) is true, but the render strips it to empty", s)
38 }
39 }
40 for _, s := range ok {
41 if !ValidReason(s) {
42 t.Errorf("ValidReason(%q) is false, but it renders as real text", s)
43 }
44 }
45
46}