From 1c5a13c9c3aacc901834f54a2b3d5a6703e6ac79 Mon Sep 17 00:00:00 2001 From: Prashant Varanasi Date: Sun, 28 Apr 2019 19:34:36 -0700 Subject: [PATCH 1/7] Disable HTMLEscape in reflect JSON encoder (#704) Fixes #700. Zap's custom JSON encoder does not escape HTML, so make encoding by the reflect-based JSON encoder work the same way. --- zapcore/json_encoder.go | 3 +++ zapcore/json_encoder_impl_test.go | 4 ++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/zapcore/json_encoder.go b/zapcore/json_encoder.go index 2dc67d81e..9aec4eada 100644 --- a/zapcore/json_encoder.go +++ b/zapcore/json_encoder.go @@ -137,6 +137,9 @@ func (enc *jsonEncoder) resetReflectBuf() { if enc.reflectBuf == nil { enc.reflectBuf = bufferpool.Get() enc.reflectEnc = json.NewEncoder(enc.reflectBuf) + + // For consistency with our custom JSON encoder. + enc.reflectEnc.SetEscapeHTML(false) } else { enc.reflectBuf.Reset() } diff --git a/zapcore/json_encoder_impl_test.go b/zapcore/json_encoder_impl_test.go index 563d5f6b6..183e2b8c1 100644 --- a/zapcore/json_encoder_impl_test.go +++ b/zapcore/json_encoder_impl_test.go @@ -195,9 +195,9 @@ func TestJSONEncoderObjectFields(t *testing.T) { }, { desc: "reflect (success)", - expected: `"k":{"loggable":"yes"}`, + expected: `"k":{"escape":"<&>","loggable":"yes"}`, f: func(e Encoder) { - assert.NoError(t, e.AddReflected("k", map[string]string{"loggable": "yes"}), "Unexpected error JSON-serializing a map.") + assert.NoError(t, e.AddReflected("k", map[string]string{"escape": "<&>", "loggable": "yes"}), "Unexpected error JSON-serializing a map.") }, }, { From cada3b3e434a735ead0d5e818f6e31d7d94af517 Mon Sep 17 00:00:00 2001 From: Nicholas Wilson Date: Mon, 29 Apr 2019 03:38:07 +0100 Subject: [PATCH 2/7] Fix inconsistency between MapObjectEncoder's AddByteString and AppendByteString (#657) --- array_test.go | 2 +- zapcore/memory_encoder.go | 2 +- zapcore/memory_encoder_test.go | 6 ++++++ 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/array_test.go b/array_test.go index 4f709f09c..961cb1cf1 100644 --- a/array_test.go +++ b/array_test.go @@ -76,7 +76,7 @@ func TestArrayWrappers(t *testing.T) { {"empty uint8s", Uint8s("", []uint8{}), []interface{}{}}, {"empty uintptrs", Uintptrs("", []uintptr{}), []interface{}{}}, {"bools", Bools("", []bool{true, false}), []interface{}{true, false}}, - {"byte strings", ByteStrings("", [][]byte{{1, 2}, {3, 4}}), []interface{}{[]byte{1, 2}, []byte{3, 4}}}, + {"byte strings", ByteStrings("", [][]byte{{1, 2}, {3, 4}}), []interface{}{"\x01\x02", "\x03\x04"}}, {"complex128s", Complex128s("", []complex128{1 + 2i, 3 + 4i}), []interface{}{1 + 2i, 3 + 4i}}, {"complex64s", Complex64s("", []complex64{1 + 2i, 3 + 4i}), []interface{}{complex64(1 + 2i), complex64(3 + 4i)}}, {"durations", Durations("", []time.Duration{1, 2}), []interface{}{time.Nanosecond, 2 * time.Nanosecond}}, diff --git a/zapcore/memory_encoder.go b/zapcore/memory_encoder.go index 6ef85b09c..dfead0829 100644 --- a/zapcore/memory_encoder.go +++ b/zapcore/memory_encoder.go @@ -158,7 +158,7 @@ func (s *sliceArrayEncoder) AppendReflected(v interface{}) error { } func (s *sliceArrayEncoder) AppendBool(v bool) { s.elems = append(s.elems, v) } -func (s *sliceArrayEncoder) AppendByteString(v []byte) { s.elems = append(s.elems, v) } +func (s *sliceArrayEncoder) AppendByteString(v []byte) { s.elems = append(s.elems, string(v)) } func (s *sliceArrayEncoder) AppendComplex128(v complex128) { s.elems = append(s.elems, v) } func (s *sliceArrayEncoder) AppendComplex64(v complex64) { s.elems = append(s.elems, v) } func (s *sliceArrayEncoder) AppendDuration(v time.Duration) { s.elems = append(s.elems, v) } diff --git a/zapcore/memory_encoder_test.go b/zapcore/memory_encoder_test.go index 5ca9577ae..7a3f51acc 100644 --- a/zapcore/memory_encoder_test.go +++ b/zapcore/memory_encoder_test.go @@ -87,6 +87,11 @@ func TestMapObjectEncoderAdd(t *testing.T) { f: func(e ObjectEncoder) { e.AddBinary("k", []byte("foo")) }, expected: []byte("foo"), }, + { + desc: "AddByteString", + f: func(e ObjectEncoder) { e.AddByteString("k", []byte("foo")) }, + expected: "foo", + }, { desc: "AddBool", f: func(e ObjectEncoder) { e.AddBool("k", true) }, @@ -228,6 +233,7 @@ func TestSliceArrayEncoderAppend(t *testing.T) { // AppendObject and AppendArray are covered by the AddObject (nested) and // AddArray (nested) cases above. {"AppendBool", func(e ArrayEncoder) { e.AppendBool(true) }, true}, + {"AppendByteString", func(e ArrayEncoder) { e.AppendByteString([]byte("foo")) }, "foo"}, {"AppendComplex128", func(e ArrayEncoder) { e.AppendComplex128(1 + 2i) }, 1 + 2i}, {"AppendComplex64", func(e ArrayEncoder) { e.AppendComplex64(1 + 2i) }, complex64(1 + 2i)}, {"AppendDuration", func(e ArrayEncoder) { e.AppendDuration(time.Second) }, time.Second}, From 5dab9368974ab1352e4245f9d33e5bce4c23a034 Mon Sep 17 00:00:00 2001 From: Prashant Varanasi Date: Mon, 29 Apr 2019 07:16:43 -0700 Subject: [PATCH 3/7] Fix call depth of standard logger in go1.12 (#706) Go1.11 includes a caller for the auto-generated wrapper within the standard library logger, which is no longer included in Go1.12. See https://github.com/uber-go/zap/issues/682#issuecomment-487442000 for more details. Fixes #682. --- global.go | 1 - global_go112.go | 26 ++++++++++++++++++++++++++ global_prego112.go | 26 ++++++++++++++++++++++++++ 3 files changed, 52 insertions(+), 1 deletion(-) create mode 100644 global_go112.go create mode 100644 global_prego112.go diff --git a/global.go b/global.go index d02232e39..c1ac0507c 100644 --- a/global.go +++ b/global.go @@ -31,7 +31,6 @@ import ( ) const ( - _stdLogDefaultDepth = 2 _loggerWriterDepth = 2 _programmerErrorTemplate = "You've found a bug in zap! Please file a bug at " + "https://github.com/uber-go/zap/issues/new and reference this error: %v" diff --git a/global_go112.go b/global_go112.go new file mode 100644 index 000000000..6b5dbda80 --- /dev/null +++ b/global_go112.go @@ -0,0 +1,26 @@ +// Copyright (c) 2019 Uber Technologies, Inc. +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. + +// See #682 for more information. +// +build go1.12 + +package zap + +const _stdLogDefaultDepth = 1 diff --git a/global_prego112.go b/global_prego112.go new file mode 100644 index 000000000..d3ab9af93 --- /dev/null +++ b/global_prego112.go @@ -0,0 +1,26 @@ +// Copyright (c) 2019 Uber Technologies, Inc. +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. + +// See #682 for more information. +// +build !go1.12 + +package zap + +const _stdLogDefaultDepth = 2 From b7d69806e1fdfd537aac899cb2f06eb0e8f87913 Mon Sep 17 00:00:00 2001 From: Prashant Varanasi Date: Mon, 29 Apr 2019 13:16:11 -0700 Subject: [PATCH 4/7] Add Go 1.12 for Travis (#707) Makefile rules have to change for 1.12 support (can't use go tool vet). Drops 1.10 as we only support current and previous release. --- .travis.yml | 2 +- Makefile | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index d586200e4..ada5ebdcc 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,8 +1,8 @@ language: go sudo: false go: - - 1.10.x - 1.11.x + - 1.12.x go_import_path: go.uber.org/zap env: global: diff --git a/Makefile b/Makefile index ef7893b3b..073e9aa91 100644 --- a/Makefile +++ b/Makefile @@ -9,7 +9,7 @@ PKG_FILES ?= *.go zapcore benchmarks buffer zapgrpc zaptest zaptest/observer int # stable release. GO_VERSION := $(shell go version | cut -d " " -f 3) GO_MINOR_VERSION := $(word 2,$(subst ., ,$(GO_VERSION))) -LINTABLE_MINOR_VERSIONS := 10 +LINTABLE_MINOR_VERSIONS := 12 ifneq ($(filter $(LINTABLE_MINOR_VERSIONS),$(GO_MINOR_VERSION)),) SHOULD_LINT := true endif @@ -45,7 +45,7 @@ ifdef SHOULD_LINT @echo "Installing test dependencies for vet..." @go test -i $(PKGS) @echo "Checking vet..." - @$(foreach dir,$(PKG_FILES),go tool vet $(VET_RULES) $(dir) 2>&1 | tee -a lint.log;) + @go vet $(VET_RULES) $(PKGS) 2>&1 | tee -a lint.log @echo "Checking lint..." @$(foreach dir,$(PKGS),golint $(dir) 2>&1 | tee -a lint.log;) @echo "Checking for unresolved FIXMEs..." From 127908a13cf4598406ce31c3905523b08b598edd Mon Sep 17 00:00:00 2001 From: Prashant Varanasi Date: Mon, 29 Apr 2019 18:44:53 -0700 Subject: [PATCH 5/7] Prep for 1.10.0 release, update CHANGELOG (#705) --- CHANGELOG.md | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 17d5b49f3..eedbee956 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,22 @@ # Changelog +## 1.10.0 (29 Apr 2019) + +Bugfixes: +* [#657][]: Fix `MapObjectEncoder.AppendByteString` not adding value as a + string. +* [#706][]: Fix incorrect call depth to determine caller in Go 1.12. + +Enhancements: +* [#610][]: Add `zaptest.WrapOptions` to wrap `zap.Option` for creating test + loggers. +* [#657][]: Don't panic when encoding a String field. +* [#704][]: Disable HTML escaping for JSON objects encoded using the + reflect-based encoder. + +Thanks to @iaroslav-ciupin, @lelenanam, @joa, @NWilson for their contributions +to this release. + ## v1.9.1 (06 Aug 2018) Bugfixes: @@ -303,3 +320,8 @@ upgrade to the upcoming stable release. [#572]: https://github.com/uber-go/zap/pull/572 [#606]: https://github.com/uber-go/zap/pull/606 [#614]: https://github.com/uber-go/zap/pull/614 +[#657]: https://github.com/uber-go/zap/pull/657 +[#706]: https://github.com/uber-go/zap/pull/706 +[#610]: https://github.com/uber-go/zap/pull/610 +[#657]: https://github.com/uber-go/zap/pull/657 +[#704]: https://github.com/uber-go/zap/pull/704 From 27376062155ad36be76b0f12cf1572a221d3a48c Mon Sep 17 00:00:00 2001 From: Prashant Varanasi Date: Mon, 29 Apr 2019 18:48:40 -0700 Subject: [PATCH 6/7] Fix changelog links for 675 --- CHANGELOG.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index eedbee956..28d10677e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,7 +10,7 @@ Bugfixes: Enhancements: * [#610][]: Add `zaptest.WrapOptions` to wrap `zap.Option` for creating test loggers. -* [#657][]: Don't panic when encoding a String field. +* [#675][]: Don't panic when encoding a String field. * [#704][]: Disable HTML escaping for JSON objects encoded using the reflect-based encoder. @@ -323,5 +323,5 @@ upgrade to the upcoming stable release. [#657]: https://github.com/uber-go/zap/pull/657 [#706]: https://github.com/uber-go/zap/pull/706 [#610]: https://github.com/uber-go/zap/pull/610 -[#657]: https://github.com/uber-go/zap/pull/657 +[#675]: https://github.com/uber-go/zap/pull/675 [#704]: https://github.com/uber-go/zap/pull/704 From 8a2ee5670ced5d94154bf385dc6a362722945daf Mon Sep 17 00:00:00 2001 From: Abhinav Gupta Date: Tue, 30 Apr 2019 08:52:29 -0700 Subject: [PATCH 7/7] README: Switch to travis-ci.com for badge (#709) --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index f4fd1cb44..304b964cb 100644 --- a/README.md +++ b/README.md @@ -128,8 +128,8 @@ pinned in zap's [glide.lock][] file. [↩](#anchor-versions) [doc-img]: https://godoc.org/go.uber.org/zap?status.svg [doc]: https://godoc.org/go.uber.org/zap -[ci-img]: https://travis-ci.org/uber-go/zap.svg?branch=master -[ci]: https://travis-ci.org/uber-go/zap +[ci-img]: https://travis-ci.com/uber-go/zap.svg?branch=master +[ci]: https://travis-ci.com/uber-go/zap [cov-img]: https://codecov.io/gh/uber-go/zap/branch/master/graph/badge.svg [cov]: https://codecov.io/gh/uber-go/zap [benchmarking suite]: https://github.com/uber-go/zap/tree/master/benchmarks