escape_test.gno
1.53 Kb · 41 lines
1package varintdemo
2
3import (
4 "strings"
5 "testing"
6
7 "gno.land/p/g1magld5ptgzaktqcexxq0pgq5lmdf0kz6re8hlv/md/v0"
8 "gno.land/p/nt/uassert/v0"
9)
10
11// The path is the visitor's text and it is rendered inside a code span, so a
12// backtick in it must not close that span and let a link through. A
13// backslash does not escape a backtick inside a span: only a wider fence
14// does, which is what md.InlineCode picks.
15func TestRenderArgCannotCloseItsCodeSpan(t *testing.T) {
16 arg := "x` [claim](https://evil.example) `"
17 out := Render("/" + arg)
18 uassert.True(t, strings.Contains(out, md.InlineCode(arg)), out)
19 uassert.False(t, strings.Contains(out, "`x\\` [claim](https://evil.example) \\``"), out)
20}
21
22// A value above MaxInt64 is one this codec carries: the unsigned line is
23// rendered, so the page must not then say the codec cannot carry it.
24func TestRenderMaxUint64DoesNotContradictItself(t *testing.T) {
25 out := Render("/18446744073709551615")
26 uassert.True(t, strings.Contains(out, "ff ff ff ff ff ff ff ff ff 01"), out)
27 uassert.False(t, strings.Contains(out, "Not an integer"), out)
28}
29
30// Neither parse succeeding is the only case that message belongs to.
31func TestRenderRejectsNonInteger(t *testing.T) {
32 out := Render("/notanumber")
33 uassert.True(t, strings.Contains(out, "Not an integer"), out)
34}
35
36// Whitespace is not trimmed: trimming would launder an input the parsers
37// refuse into a clean encoding of a value nobody submitted.
38func TestRenderDoesNotTrim(t *testing.T) {
39 out := Render("/ 300 ")
40 uassert.True(t, strings.Contains(out, "Not an integer"), out)
41}