Skip to content

Commit

Permalink
add json/fix.go
Browse files Browse the repository at this point in the history
Signed-off-by: Simon Behar <[email protected]>
  • Loading branch information
simster7 committed Mar 8, 2021
1 parent 4233d0b commit 8c69f4f
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
11 changes: 11 additions & 0 deletions util/json/fix.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package json

import "strings"

func Fix(s string) string {
// https://stackoverflow.com/questions/28595664/how-to-stop-json-marshal-from-escaping-and/28596225
s = strings.Replace(s, "\\u003c", "<", -1)
s = strings.Replace(s, "\\u003e", ">", -1)
s = strings.Replace(s, "\\u0026", "&", -1)
return s
}
13 changes: 13 additions & 0 deletions util/json/fix_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package json

import (
"testing"

"github.com/stretchr/testify/assert"
)

func Test_Fix(t *testing.T) {
assert.Equal(t, "<", Fix("\\u003c"))
assert.Equal(t, ">", Fix("\\u003e"))
assert.Equal(t, "&", Fix("\\u0026"))
}

0 comments on commit 8c69f4f

Please sign in to comment.