diff --git a/HISTORY.md b/HISTORY.md index e234313..60e3900 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -1,5 +1,11 @@ ## ✒ 历史版本的特性介绍 (Features in old versions) +### v1.5.9-alpha + +> 此版本发布于 2024-01-09 + +* 去除对 \ 和 " 的转义 + ### v1.5.8-alpha > 此版本发布于 2023-12-27 diff --git a/doc.go b/doc.go index 93cc91f..2fb1d33 100644 --- a/doc.go +++ b/doc.go @@ -317,5 +317,5 @@ package logit // import "github.com/FishGoddess/logit" const ( // Version is the version string representation of logit. - Version = "v1.5.8-alpha" + Version = "v1.5.9-alpha" ) diff --git a/handler/escape.go b/handler/escape.go index 6bb724c..abdc0e4 100644 --- a/handler/escape.go +++ b/handler/escape.go @@ -20,17 +20,15 @@ import ( ) // needEscapedByte returns if value need to escape. -// The main character should be escaped is ascii less than \u0020 and \ and ". +// The main character should be escaped is ascii less than \u0020. func needEscapedByte(value byte) bool { - return value < 32 || value == '"' || value == '\\' + return value < 32 } // appendEscapedByte appends escaped value to dst. -// The main character should be escaped is ascii less than \u0020 and \ and ". +// The main character should be escaped is ascii less than \u0020. func appendEscapedByte(dst []byte, value byte) []byte { switch value { - case '"', '\\': - return append(dst, '\\', value) case '\b': return append(dst, '\\', 'b') case '\f': @@ -57,7 +55,7 @@ func appendEscapedByte(dst []byte, value byte) []byte { } // appendEscapedString appends escaped value to dst. -// The main character should be escaped is ascii less than \u0020 and \ and ". +// The main character should be escaped is ascii less than \u0020. func appendEscapedString(dst []byte, value string) []byte { start := 0 escaped := false diff --git a/handler/escape_test.go b/handler/escape_test.go index 1b0129c..ec80a0e 100644 --- a/handler/escape_test.go +++ b/handler/escape_test.go @@ -19,7 +19,7 @@ import "testing" // go test -v -cover -count=1 -test.cpu=1 -run=^TestAppendEscapedByte$ func TestAppendEscapedByte(t *testing.T) { testcases := []byte{'a', '0', '\n', '\t', '\\', '\b', '\f', '\r', '"'} - want := "a0\\n\\t\\\\\\b\\f\\r\\\"" + want := `a0\n\t\\b\f\r"` buffer := make([]byte, 0, 16) for _, b := range testcases { @@ -33,8 +33,8 @@ func TestAppendEscapedByte(t *testing.T) { // go test -v -cover -count=1 -test.cpu=1 -run=^TestAppendEscapedString$ func TestAppendEscapedString(t *testing.T) { - testcases := []string{"a0国\n\t\\\b\f\r\""} - want := "a0国\\n\\t\\\\\\b\\f\\r\\\"" + testcases := []string{"a0国\n\t\\b\f\r\""} + want := `a0国\n\t\b\f\r"` buffer := make([]byte, 0, 16) for _, str := range testcases {