diff options
author | Frédéric Guillot <fred@miniflux.net> | 2017-11-19 21:10:04 -0800 |
---|---|---|
committer | Frédéric Guillot <fred@miniflux.net> | 2017-11-19 22:01:46 -0800 |
commit | 8ffb773f43c8dc54801ca1d111854e7e881c93c9 (patch) | |
tree | 38133a2fc612597a75fed1d13e5b4042f58a2b7e /vendor/github.com/tdewolff/parse/html/util_test.go |
First commit
Diffstat (limited to 'vendor/github.com/tdewolff/parse/html/util_test.go')
-rw-r--r-- | vendor/github.com/tdewolff/parse/html/util_test.go | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/vendor/github.com/tdewolff/parse/html/util_test.go b/vendor/github.com/tdewolff/parse/html/util_test.go new file mode 100644 index 0000000..3722a08 --- /dev/null +++ b/vendor/github.com/tdewolff/parse/html/util_test.go @@ -0,0 +1,43 @@ +package html // import "github.com/tdewolff/parse/html" + +import ( + "testing" + + "github.com/tdewolff/test" +) + +func TestEscapeAttrVal(t *testing.T) { + var escapeAttrValTests = []struct { + attrVal string + expected string + }{ + {"xyz", "xyz"}, + {"", ""}, + {"x&z", "x&z"}, + {"x/z", "x/z"}, + {"x'z", "\"x'z\""}, + {"x\"z", "'x\"z'"}, + {"'x\"z'", "'x\"z'"}, + {"'x'\"'z'", "\"x'"'z\""}, + {"\"x"'"z\"", "'x\"'\"z'"}, + {"\"x'z\"", "\"x'z\""}, + {"'x"z'", "'x\"z'"}, + {"'x\">'", "'x\">'"}, + {"You're encouraged to log in; however, it's not mandatory. [o]", "\"You're encouraged to log in; however, it's not mandatory. [o]\""}, + {"a'b=\"\"", "'a'b=\"\"'"}, + {"x<z", "\"x<z\""}, + {"'x\"'\"z'", "'x\"'\"z'"}, + } + var buf []byte + for _, tt := range escapeAttrValTests { + t.Run(tt.attrVal, func(t *testing.T) { + b := []byte(tt.attrVal) + orig := b + if len(b) > 1 && (b[0] == '"' || b[0] == '\'') && b[0] == b[len(b)-1] { + b = b[1 : len(b)-1] + } + val := EscapeAttrVal(&buf, orig, []byte(b)) + test.String(t, string(val), tt.expected) + }) + } +} |