Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion v2/goi18n/marshal.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,12 @@ func marshalValue(messageTemplates map[string]*i18n.MessageTemplate, sourceLangu
func marshal(v interface{}, format string) ([]byte, error) {
switch format {
case "json":
return json.MarshalIndent(v, "", " ")
var buf bytes.Buffer
enc := json.NewEncoder(&buf)
enc.SetEscapeHTML(false)
enc.SetIndent("", " ")
err := enc.Encode(v)
return buf.Bytes(), err
case "toml":
var buf bytes.Buffer
enc := toml.NewEncoder(&buf)
Expand Down
21 changes: 21 additions & 0 deletions v2/goi18n/marshal_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package main

import "testing"

func TestMarshal(t *testing.T) {
actual, err := marshal(map[string]string{
"&<key>": "&<val>",
}, "json")

if err != nil {
t.Fatal(err)
}

expected := `{
"&<key>": "&<val>"
}
`
if a := string(actual); a != expected {
t.Fatalf("\nexpected:\n%s\n\ngot\n%s", expected, a)
}
}