Commit 9dd746c4 authored by David Symonds's avatar David Symonds

encoding/json: drop MarshalForHTML; gofix calls to Marshal.

I've elected to omit escaping the output of Marshalers for now.
I haven't thought through the implications of that;
I suspect that double escaping might be the undoing of that idea.

Fixes #3127.

R=golang-dev, r
CC=golang-dev
https://golang.org/cl/5694098
parent 740d5038
...@@ -38,6 +38,12 @@ var go1renameReplace = []rename{ ...@@ -38,6 +38,12 @@ var go1renameReplace = []rename{
Old: "*des.TripleDESCipher", Old: "*des.TripleDESCipher",
New: "cipher.Block", New: "cipher.Block",
}, },
{
OldImport: "encoding/json",
NewImport: "",
Old: "json.MarshalForHTML",
New: "json.Marshal",
},
{ {
OldImport: "net/url", OldImport: "net/url",
NewImport: "", NewImport: "",
......
...@@ -16,6 +16,7 @@ var go1renameTests = []testCase{ ...@@ -16,6 +16,7 @@ var go1renameTests = []testCase{
import ( import (
"crypto/aes" "crypto/aes"
"crypto/des" "crypto/des"
"encoding/json"
"net/url" "net/url"
"os" "os"
"runtime" "runtime"
...@@ -25,6 +26,7 @@ var ( ...@@ -25,6 +26,7 @@ var (
_ *aes.Cipher _ *aes.Cipher
_ *des.Cipher _ *des.Cipher
_ *des.TripleDESCipher _ *des.TripleDESCipher
_ = json.MarshalForHTML
_ = aes.New() _ = aes.New()
_ = url.Parse _ = url.Parse
_ = url.ParseWithReference _ = url.ParseWithReference
...@@ -39,6 +41,7 @@ var ( ...@@ -39,6 +41,7 @@ var (
import ( import (
"crypto/aes" "crypto/aes"
"crypto/cipher" "crypto/cipher"
"encoding/json"
"net/url" "net/url"
"runtime" "runtime"
"syscall" "syscall"
...@@ -48,6 +51,7 @@ var ( ...@@ -48,6 +51,7 @@ var (
_ cipher.Block _ cipher.Block
_ cipher.Block _ cipher.Block
_ cipher.Block _ cipher.Block
_ = json.Marshal
_ = aes.New() _ = aes.New()
_ = url.Parse _ = url.Parse
_ = url.Parse _ = url.Parse
......
...@@ -239,16 +239,6 @@ func TestEscape(t *testing.T) { ...@@ -239,16 +239,6 @@ func TestEscape(t *testing.T) {
} }
} }
func TestHTMLEscape(t *testing.T) {
b, err := MarshalForHTML("foobarbaz<>&quux")
if err != nil {
t.Fatalf("MarshalForHTML error: %v", err)
}
if !bytes.Equal(b, []byte(`"foobarbaz\u003c\u003e\u0026quux"`)) {
t.Fatalf("Unexpected encoding of \"<>&\": %s", b)
}
}
// WrongString is a struct that's misusing the ,string modifier. // WrongString is a struct that's misusing the ,string modifier.
type WrongString struct { type WrongString struct {
Message string `json:"result,string"` Message string `json:"result,string"`
......
...@@ -123,17 +123,6 @@ func MarshalIndent(v interface{}, prefix, indent string) ([]byte, error) { ...@@ -123,17 +123,6 @@ func MarshalIndent(v interface{}, prefix, indent string) ([]byte, error) {
return buf.Bytes(), nil return buf.Bytes(), nil
} }
// MarshalForHTML is like Marshal but applies HTMLEscape to the output.
func MarshalForHTML(v interface{}) ([]byte, error) {
b, err := Marshal(v)
if err != nil {
return nil, err
}
var buf bytes.Buffer
HTMLEscape(&buf, b)
return buf.Bytes(), nil
}
// HTMLEscape appends to dst the JSON-encoded src with <, >, and & // HTMLEscape appends to dst the JSON-encoded src with <, >, and &
// characters inside string literals changed to \u003c, \u003e, \u0026 // characters inside string literals changed to \u003c, \u003e, \u0026
// so that the JSON will be safe to embed inside HTML <script> tags. // so that the JSON will be safe to embed inside HTML <script> tags.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment