|
@@ -202,6 +202,44 @@ func TestPrefix(t *testing.T) {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+func TestEscapeXML(t *testing.T) {
|
|
|
|
|
+ // These test cases aren't exhaustive, and there is more than one way to
|
|
|
|
|
+ // escape e.g. a quot (as """ or """) or an apos. We presume that
|
|
|
|
|
+ // the encoding/xml package tests xml.EscapeText more thoroughly. This test
|
|
|
|
|
+ // here is just a sanity check for this package's escapeXML function, and
|
|
|
|
|
+ // its attempt to provide a fast path (and avoid a bytes.Buffer allocation)
|
|
|
|
|
+ // when escaping filenames is obviously a no-op.
|
|
|
|
|
+ testCases := map[string]string{
|
|
|
|
|
+ "": "",
|
|
|
|
|
+ " ": " ",
|
|
|
|
|
+ "&": "&",
|
|
|
|
|
+ "*": "*",
|
|
|
|
|
+ "+": "+",
|
|
|
|
|
+ ",": ",",
|
|
|
|
|
+ "-": "-",
|
|
|
|
|
+ ".": ".",
|
|
|
|
|
+ "/": "/",
|
|
|
|
|
+ "0": "0",
|
|
|
|
|
+ "9": "9",
|
|
|
|
|
+ ":": ":",
|
|
|
|
|
+ "<": "<",
|
|
|
|
|
+ ">": ">",
|
|
|
|
|
+ "A": "A",
|
|
|
|
|
+ "_": "_",
|
|
|
|
|
+ "a": "a",
|
|
|
|
|
+ "~": "~",
|
|
|
|
|
+ "\u0201": "\u0201",
|
|
|
|
|
+ "&": "&amp;",
|
|
|
|
|
+ "foo&<b/ar>baz": "foo&<b/ar>baz",
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ for in, want := range testCases {
|
|
|
|
|
+ if got := escapeXML(in); got != want {
|
|
|
|
|
+ t.Errorf("in=%q: got %q, want %q", in, got, want)
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
func TestFilenameEscape(t *testing.T) {
|
|
func TestFilenameEscape(t *testing.T) {
|
|
|
hrefRe := regexp.MustCompile(`<D:href>([^<]*)</D:href>`)
|
|
hrefRe := regexp.MustCompile(`<D:href>([^<]*)</D:href>`)
|
|
|
displayNameRe := regexp.MustCompile(`<D:displayname>([^<]*)</D:displayname>`)
|
|
displayNameRe := regexp.MustCompile(`<D:displayname>([^<]*)</D:displayname>`)
|