File: cherry-pick-from-upstream.patch

package info (click to toggle)
golang-github-mattermost-xml-roundtrip-validator 0.1.0-4
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 152 kB
  • sloc: makefile: 5
file content (178 lines) | stat: -rw-r--r-- 7,930 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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
Description: upstream changed some things for newer golang versions
Index: golang-github-mattermost-xml-roundtrip-validator/reader_test.go
===================================================================
--- golang-github-mattermost-xml-roundtrip-validator.orig/reader_test.go	2022-02-01 18:58:20.586211166 +0100
+++ golang-github-mattermost-xml-roundtrip-validator/reader_test.go	2022-02-01 19:08:54.138117707 +0100
@@ -36,7 +36,7 @@
 	assert.NoError(t, err, "Should not error on a valid XML document")
 
 	// an invalid document should still error :
-	zipped = flateIt(t, `<x::Root/>`)
+	zipped = flateIt(t, `<Root>]]></Root>`)
 
 	err = Validate(zipped)
 	assert.Error(t, err, "Should error on an invalid XML document")
Index: golang-github-mattermost-xml-roundtrip-validator/validator_test.go
===================================================================
--- golang-github-mattermost-xml-roundtrip-validator.orig/validator_test.go	2022-02-01 18:58:20.586211166 +0100
+++ golang-github-mattermost-xml-roundtrip-validator/validator_test.go	2022-02-01 19:17:49.226038458 +0100
@@ -3,7 +3,6 @@
 import (
 	"bytes"
 	"encoding/xml"
-	"errors"
 	"fmt"
 	"io"
 	"strings"
@@ -34,105 +33,6 @@
 	}
 }
 
-func TestColonsInLocalNames(t *testing.T) {
-	var err error
-
-	err = Validate(bytes.NewBufferString(`<x::Root/>`))
-	require.Error(t, err, "Should error on input with colons in the root element's name")
-	require.Equal(t, XMLRoundtripError{
-		Expected: tokenize(t, `<x::Root/>`),
-		Observed: tokenize(t, `<Root xmlns="x"/>`),
-	}, errors.Unwrap(err), "Error should contain expected token and mutation")
-
-	err = Validate(bytes.NewBufferString(`<Root><x::Element></::Element></Root>`))
-	require.Error(t, err, "Should error on input with colons in a nested tag's name")
-	require.Equal(t, XMLRoundtripError{
-		Expected: tokenize(t, `<x::Element>`),
-		Observed: tokenize(t, `<Element xmlns="x">`),
-	}, errors.Unwrap(err), "Error should contain expected token and mutation")
-
-	err = Validate(bytes.NewBufferString(`<Root><Element ::attr="foo"></Element></Root>`))
-	require.Error(t, err, "Should error on input with colons in an attribute's name")
-	require.Equal(t, XMLRoundtripError{
-		Expected: tokenize(t, `<Element ::attr="foo">`),
-		Observed: tokenize(t, `<Element attr="foo">`),
-	}, errors.Unwrap(err), "Error should contain expected token and mutation")
-
-	err = Validate(bytes.NewBufferString(`<Root></x::Element></Root>`))
-	require.Error(t, err, "Should error on input with colons in an end tag's name")
-	require.Equal(t, XMLRoundtripError{
-		Expected: tokenize(t, `</x::Element>`),
-		Observed: tokenize(t, `</Element>`),
-	}, errors.Unwrap(err), "Error should contain expected token and mutation")
-}
-
-func TestEmptyNames(t *testing.T) {
-	var err error
-
-	err = Validate(bytes.NewBufferString(`<x:>`))
-	require.Error(t, err, "Should error on start element with no local name")
-
-	err = Validate(bytes.NewBufferString(`</x:>`))
-	require.Error(t, err, "Should error on end element with no local name")
-}
-
-func TestEmptyAttributes(t *testing.T) {
-	var err error
-
-	err = Validate(bytes.NewBufferString(`<Root :="value"/>`))
-	require.Error(t, err, "Should error on input with empty attribute names")
-	require.Equal(t, XMLRoundtripError{
-		Expected: tokenize(t, `<Root :="value"/>`),
-		Observed: tokenize(t, `<Root/>`),
-	}, errors.Unwrap(err), "Error should contain expected token and mutation")
-
-	err = Validate(bytes.NewBufferString(`<Root x:="value"/>`))
-	require.Error(t, err, "Should error on input with empty attribute local names")
-	require.Equal(t, XMLRoundtripError{
-		Expected: tokenize(t, `<Root x:="value"/>`),
-		Observed: tokenize(t, `<Root/>`),
-	}, errors.Unwrap(err), "Error should contain expected token and mutation")
-
-	err = Validate(bytes.NewBufferString(`<Root xmlns="x" xmlns:="y"></Root>`))
-	require.Error(t, err, "Should error on input with empty xmlns local names")
-	require.Equal(t, XMLRoundtripError{
-		Expected: tokenize(t, `<Root xmlns="x" xmlns:="y">`),
-		Observed: tokenize(t, `<Root xmlns="x">`),
-	}, errors.Unwrap(err), "Error should contain expected token and mutation")
-
-	validXmlns := `<Root xmlns="http://example.com/"/>`
-	require.NoError(t, Validate(bytes.NewBufferString(validXmlns)), "Should pass on input with valid xmlns attributes")
-}
-
-func TestDirectives(t *testing.T) {
-	var err error
-
-	err = Validate(bytes.NewBufferString(
-		`<Root>
-			<! <<!-- -->!-->"--> " >
-			<! ">" <X/>>
-		</Root>`))
-	require.Error(t, err, "Should error on bad directive")
-	require.Equal(t, &xml.SyntaxError{Msg: io.ErrUnexpectedEOF.Error(), Line: 1},
-		errors.Unwrap(err), "Round trip should fail with unexpected EOF")
-
-	err = Validate(bytes.NewBufferString(`<Root><! <<!-- -->!-- x --> y></Root>`))
-	require.Error(t, err, "Should error on bad directive")
-	require.Equal(t, XMLRoundtripError{
-		Expected: tokenize(t, `<! <<!-- -->!-- x --> y>`),
-		Observed: tokenize(t, `<!  y>`),
-	}, errors.Unwrap(err), "Error should contain expected token and mutation")
-
-	goodDirectives := []string{
-		`<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">`,
-		`<! ">" <X/>>`,
-		`<!name <!-- comment --><nesting <more nesting>>>`,
-	}
-	for _, doc := range goodDirectives {
-		require.NoError(t, Validate(bytes.NewBufferString(doc)), "Should pass on good directives")
-	}
-}
-
 func TestUnparseableXML(t *testing.T) {
 	var err error
 
@@ -148,33 +48,19 @@
 
 	errs := ValidateAll(bytes.NewBufferString(
 		`<Root ::attr="x">]]><x::Element/></Root>`))
-	require.Len(t, errs, 2, "Should return exactly two errors")
-	require.Error(t, errs[0], "Should error on bad attribute")
-	require.Error(t, errs[1], "Should error on unexpected ']]>' sequence")
-	require.IsType(t, &xml.SyntaxError{}, errs[1], "Error should be an &xml.SyntaxError")
-}
-
-func TestValidateAll(t *testing.T) {
-	var err XMLValidationError
 
-	xmlBytes := []byte("<Root>\r\n    <! <<!-- -->!-- x --> y>\r\n    <Element ::attr=\"foo\"></x::Element>\r\n</Root>")
-	errs := ValidateAll(bytes.NewBuffer(xmlBytes))
-	require.Equal(t, 3, len(errs), "Should return three errors")
-
-	err = errs[0].(XMLValidationError)
-	require.Equal(t, int64(2), err.Line, "First error should be on line 2")
-	require.Equal(t, int64(5), err.Column, "First error should be on column 5")
-	require.Equal(t, []byte(`<! <<!-- -->!-- x --> y>`), xmlBytes[err.Start:err.End], "First error should point to the correct bytes in the original XML")
-
-	err = errs[1].(XMLValidationError)
-	require.Equal(t, int64(3), err.Line, "Second error should be on line 3")
-	require.Equal(t, int64(5), err.Column, "Second error should be on column 5")
-	require.Equal(t, []byte(`<Element ::attr="foo">`), xmlBytes[err.Start:err.End], "Second error should point to the correct bytes in the original XML")
-
-	err = errs[2].(XMLValidationError)
-	require.Equal(t, int64(3), err.Line, "Third error should be on line 3")
-	require.Equal(t, int64(27), err.Column, "Third error should be on column 27")
-	require.Equal(t, []byte(`</x::Element>`), xmlBytes[err.Start:err.End], "Third error should point to the correct bytes in the original XML")
+	if el := tokenize(t, `<Root :="value"/>`).(xml.StartElement); el.Attr[0].Name.Local == `:` {
+		// go1.17+
+		require.Len(t, errs, 1, "Should return exactly one error")
+		require.Error(t, errs[0], "Should error on unexpected ']]>' sequence")
+		require.IsType(t, &xml.SyntaxError{}, errs[0], "Error should be an &xml.SyntaxError")
+	} else {
+		// go1.16 and older
+		require.Len(t, errs, 2, "Should return exactly two errors")
+		require.Error(t, errs[0], "Should error on bad attribute")
+		require.Error(t, errs[1], "Should error on unexpected ']]>' sequence")
+		require.IsType(t, &xml.SyntaxError{}, errs[1], "Error should be an &xml.SyntaxError")
+	}
 }
 
 func TestTokenEquals(t *testing.T) {