44 "encoding/json"
55 "fmt"
66 "sort"
7+ "strings"
78 "testing"
89)
910
@@ -113,6 +114,8 @@ func TestMarshalJSON(t *testing.T) {
113114 o .Set ("number" , 3 )
114115 // string
115116 o .Set ("string" , "x" )
117+ // string
118+ o .Set ("specialstring" , "\\ .<>[]{}_-" )
116119 // new value keeps key in old position
117120 o .Set ("number" , 4 )
118121 // keys not sorted alphabetically
@@ -138,7 +141,7 @@ func TestMarshalJSON(t *testing.T) {
138141 }
139142 s := string (b )
140143 // check json is correctly ordered
141- if s != `{"number":4,"string":"x","z":1,"a":2,"b":3,"slice":["1",1],"orderedmap":{"e":1,"a":2},"test\"ing":9}` {
144+ if s != `{"number":4,"string":"x","specialstring":"\\.\u003c\u003e[]{}_-"," z":1,"a":2,"b":3,"slice":["1",1],"orderedmap":{"e":1,"a":2},"test\"ing":9}` {
142145 t .Error ("JSON Marshal value is incorrect" , s )
143146 }
144147 // convert to indented json
@@ -150,6 +153,7 @@ func TestMarshalJSON(t *testing.T) {
150153 ei := `{
151154 "number": 4,
152155 "string": "x",
156+ "specialstring": "\\.\u003c\u003e[]{}_-",
153157 "z": 1,
154158 "a": 2,
155159 "b": 3,
@@ -170,6 +174,23 @@ func TestMarshalJSON(t *testing.T) {
170174 }
171175}
172176
177+ func TestMarshalJSONNoEscapeHTML (t * testing.T ) {
178+ o := New ()
179+ o .SetEscapeHTML (false )
180+ // string special characters
181+ o .Set ("specialstring" , "\\ .<>[]{}_-" )
182+ // convert to json
183+ b , err := o .MarshalJSON ()
184+ if err != nil {
185+ t .Error ("Marshalling json" , err )
186+ }
187+ s := strings .Replace (string (b ), "\n " , "" , - 1 )
188+ // check json is correctly ordered
189+ if s != `{"specialstring":"\\.<>[]{}_-"}` {
190+ t .Error ("JSON Marshal value is incorrect" , s )
191+ }
192+ }
193+
173194func TestUnmarshalJSON (t * testing.T ) {
174195 s := `{
175196 "number": 4,
0 commit comments