File: invalid_text_test.go

package info (click to toggle)
golang-github-dhowett-go-plist 0.0~git20181124.0.591f970-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 376 kB
  • sloc: makefile: 2
file content (54 lines) | stat: -rw-r--r-- 1,570 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package plist

import (
	"strings"
	"testing"
)

var InvalidTextPlists = []struct {
	Name string
	Data string
}{
	{"Truncated array", "("},
	{"Truncated dictionary", "{a=b;"},
	{"Truncated dictionary 2", "{"},
	{"Unclosed nested array", "{0=(/"},
	{"Unclosed dictionary", "{0=/"},
	{"Broken GNUStep data", "(<*I5>,<*I5>,<*I5>,<*I5>,*I16777215>,<*I268435455>,<*I4294967295>,<*I18446744073709551615>,)"},
	{"Truncated nested array", "{0=(((/"},
	{"Truncated dictionary with comment-like", "{/"},
	{"Truncated array with comment-like", "(/"},
	{"Truncated array with empty data", "(<>"},
	{"Bad Extended Character", "{¬=A;}"},
	{"Missing Equals in Dictionary", `{"A"A;}`},
	{"Missing Semicolon in Dictionary", `{"A"=A}`},
	{"Invalid GNUStep type", "<*F33>"},
	{"Invalid GNUStep int", "(<*I>"},
	{"Invalid GNUStep date", "<*D5>"},
	{"Truncated GNUStep value", "<*I3"},
	{"Invalid data", "<EQ>"},
	{"Truncated unicode escape", `"\u231`},
	{"Truncated hex escape", `"\x2`},
	{"Truncated octal escape", `"\02`},
	{"Truncated data", `<33`},
	{"Uneven data", `<3>`},
	{"Truncated block comment", `/* hello`},
	{"Truncated quoted string", `"hi`},
	{"Garbage after end of non-string", "<ab> cde"},
	{"Broken UTF-16", "\xFE\xFF\x01"},
}

func TestInvalidTextPlists(t *testing.T) {
	for _, test := range InvalidTextPlists {
		subtest(t, test.Name, func(t *testing.T) {
			var obj interface{}
			buf := strings.NewReader(test.Data)
			err := NewDecoder(buf).Decode(&obj)
			if err == nil {
				t.Fatal("invalid plist failed to throw error")
			} else {
				t.Log(err)
			}
		})
	}
}