Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/gohugoio/go-i18n.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNick Snyder <nickdsnyder@gmail.com>2020-09-29 07:14:03 +0300
committerGitHub <noreply@github.com>2020-09-29 07:14:03 +0300
commit703c3bde3ea09b5f449581f4cb30f681e11351a3 (patch)
treedbf8938daf293e99f2781e69c44ff2171dc3ed5c
parente2aedcfb27c41ac8dacb3e09868b18eeb5d4bc57 (diff)
Do not encode HTML entities in JSON message files (#228)v2.1.1
-rw-r--r--v2/goi18n/marshal.go7
-rw-r--r--v2/goi18n/marshal_test.go21
2 files changed, 27 insertions, 1 deletions
diff --git a/v2/goi18n/marshal.go b/v2/goi18n/marshal.go
index 751b698..a6cc762 100644
--- a/v2/goi18n/marshal.go
+++ b/v2/goi18n/marshal.go
@@ -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)
diff --git a/v2/goi18n/marshal_test.go b/v2/goi18n/marshal_test.go
new file mode 100644
index 0000000..de6b392
--- /dev/null
+++ b/v2/goi18n/marshal_test.go
@@ -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)
+ }
+}