summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorShulhan <ms@kilabit.info>2022-08-28 21:22:51 +0700
committerShulhan <ms@kilabit.info>2022-08-28 21:24:59 +0700
commit7e1712bac3bb7c2d2d406c8b680c74b564384437 (patch)
tree4fdf8f2bc2f635823560cafb1bd3ad08fae055ca
parent2fc316d82169d7ca1541904faca83d0a155b3ed4 (diff)
downloadpakakeh.go-7e1712bac3bb7c2d2d406c8b680c74b564384437.tar.xz
lib/json: remove solidus (slash) being escaped/unescaped
The standard json package does not escape the solidus, even though the RFC said so. Someone also report this as an error in RFC [1] by removing solidus from list of escaped characters but the author itself reject it. [1] https://www.rfc-editor.org/errata/eid3159
-rw-r--r--lib/json/json.go9
-rw-r--r--lib/json/json_test.go4
2 files changed, 6 insertions, 7 deletions
diff --git a/lib/json/json.go b/lib/json/json.go
index bd8bd204..bbd2be16 100644
--- a/lib/json/json.go
+++ b/lib/json/json.go
@@ -21,7 +21,6 @@ const (
const (
bDoubleQuote = '"'
bRevSolidus = '\\'
- bSolidus = '/'
bBackspace = '\b'
bFormFeed = '\f'
bLineFeed = '\n'
@@ -30,7 +29,7 @@ const (
)
// Escape the following character: `"` (quotation mark),
-// `\` (reverse solidus), `/` (solidus), `\b` (backspace), `\f` (formfeed),
+// `\` (reverse solidus), `\b` (backspace), `\f` (formfeed),
// `\n` (newline), `\r` (carriage return`), `\t` (horizontal tab), and control
// character from 0 - 31.
//
@@ -41,7 +40,7 @@ func Escape(in []byte) []byte {
var buf bytes.Buffer
for x := 0; x < len(in); x++ {
- if in[x] == bDoubleQuote || in[x] == bRevSolidus || in[x] == bSolidus {
+ if in[x] == bDoubleQuote || in[x] == bRevSolidus {
buf.WriteByte(bRevSolidus)
buf.WriteByte(in[x])
continue
@@ -83,7 +82,7 @@ func Escape(in []byte) []byte {
}
// EscapeString escape the following character: `"` (quotation mark),
-// `\` (reverse solidus), `/` (solidus), `\b` (backspace), `\f` (formfeed),
+// `\` (reverse solidus), `\b` (backspace), `\f` (formfeed),
// `\n` (newline), `\r` (carriage return`), `\t` (horizontal tab), and control
// character from 0 - 31.
//
@@ -220,7 +219,7 @@ func Unescape(in []byte, strict bool) ([]byte, error) {
esc = false
continue
}
- if in[x] == bDoubleQuote || in[x] == bRevSolidus || in[x] == bSolidus {
+ if in[x] == bDoubleQuote || in[x] == bRevSolidus {
buf.WriteByte(in[x])
esc = false
continue
diff --git a/lib/json/json_test.go b/lib/json/json_test.go
index faab6899..bd246782 100644
--- a/lib/json/json_test.go
+++ b/lib/json/json_test.go
@@ -12,7 +12,7 @@ import (
func TestEscape(t *testing.T) {
in := []byte("\"\\/\b\f\n\r\t")
- exp := []byte(`\"\\\/\b\f\n\r\t`)
+ exp := []byte(`\"\\/\b\f\n\r\t`)
got := Escape(in)
test.Assert(t, "Escape", exp, got)
}
@@ -27,7 +27,7 @@ func TestEscapeString(t *testing.T) {
}, {
in: ` this\ is
//\"☺"`,
- exp: `\tthis\\ is\n\t\t\/\/\\\"☺\"`,
+ exp: `\tthis\\ is\n\t\t//\\\"☺\"`,
}, {
in: `  `, exp: `\u0002\b\f\u000E\u000F\u0010\u0014\u001E\u001F `,
}}