]> Cypherpunks repositories - gostls13.git/commitdiff
encoding/json: drop MarshalForHTML; gofix calls to Marshal.
authorDavid Symonds <dsymonds@golang.org>
Tue, 28 Feb 2012 00:41:16 +0000 (11:41 +1100)
committerDavid Symonds <dsymonds@golang.org>
Tue, 28 Feb 2012 00:41:16 +0000 (11:41 +1100)
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

src/cmd/fix/go1rename.go
src/cmd/fix/go1rename_test.go
src/pkg/encoding/json/decode_test.go
src/pkg/encoding/json/encode.go

index 2995880c300667f97f9f9d53e434a538c2afa189..4b666720b0e1fa00649da58e2eb00e7cb4e4a69c 100644 (file)
@@ -38,6 +38,12 @@ var go1renameReplace = []rename{
                Old:       "*des.TripleDESCipher",
                New:       "cipher.Block",
        },
+       {
+               OldImport: "encoding/json",
+               NewImport: "",
+               Old:       "json.MarshalForHTML",
+               New:       "json.Marshal",
+       },
        {
                OldImport: "net/url",
                NewImport: "",
index 02eaea6a541965bdf79bbda27eb30588e89b0d39..481ebea8e7bb2fcd4575a751ba7507d985235aba 100644 (file)
@@ -16,6 +16,7 @@ var go1renameTests = []testCase{
 import (
        "crypto/aes"
        "crypto/des"
+       "encoding/json"
        "net/url"
        "os"
        "runtime"
@@ -25,6 +26,7 @@ var (
        _ *aes.Cipher
        _ *des.Cipher
        _ *des.TripleDESCipher
+       _ = json.MarshalForHTML
        _ = aes.New()
        _ = url.Parse
        _ = url.ParseWithReference
@@ -39,6 +41,7 @@ var (
 import (
        "crypto/aes"
        "crypto/cipher"
+       "encoding/json"
        "net/url"
        "runtime"
        "syscall"
@@ -48,6 +51,7 @@ var (
        _ cipher.Block
        _ cipher.Block
        _ cipher.Block
+       _ = json.Marshal
        _ = aes.New()
        _ = url.Parse
        _ = url.Parse
index 0eec586a9bb73eee8fbe37ccb5d7529fc3116a75..d758758d97816352b6c50bc2451cb2cea3d6d510 100644 (file)
@@ -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.
 type WrongString struct {
        Message string `json:"result,string"`
index 8a794b79bd5bb5c659466c70b75cf4886063351c..7f5deed94d6737b7dc93c3bcf32def81352ff219 100644 (file)
@@ -123,17 +123,6 @@ func MarshalIndent(v interface{}, prefix, indent string) ([]byte, error) {
        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 &
 // characters inside string literals changed to \u003c, \u003e, \u0026
 // so that the JSON will be safe to embed inside HTML <script> tags.