expvar: Ensure strings are written as valid JSON.
Change-Id: I5147dbf4e85cf42cd1f32c57861e4c16d9dbd049
Reviewed-on: https://go-review.googlesource.com/21529
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Reviewed-by: Andrew Gerrand <adg@golang.org>
diff --git a/src/expvar/expvar_test.go b/src/expvar/expvar_test.go
index 385fea8..7b1c9df 100644
--- a/src/expvar/expvar_test.go
+++ b/src/expvar/expvar_test.go
@@ -142,8 +142,14 @@
t.Errorf("name.s = %q, want \"Mike\"", name.s)
}
- if s := name.String(); s != "\"Mike\"" {
- t.Errorf("reqs.String() = %q, want \"\"Mike\"\"", s)
+ if s, want := name.String(), `"Mike"`; s != want {
+ t.Errorf("from %q, name.String() = %q, want %q", name.s, s, want)
+ }
+
+ // Make sure we produce safe JSON output.
+ name.Set(`<`)
+ if s, want := name.String(), "\"\\u003c\""; s != want {
+ t.Errorf("from %q, name.String() = %q, want %q", name.s, s, want)
}
}