From 1f456c5134c2b82406bbb175585a77842c7de23e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mike=20Schw=C3=B6rer?= Date: Sun, 15 Sep 2024 21:25:21 +0200 Subject: [PATCH] v0.0.512 --- goextVersion.go | 4 ++-- gojson/encode.go | 12 ++++++++---- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/goextVersion.go b/goextVersion.go index 1f83311..5fcc869 100644 --- a/goextVersion.go +++ b/goextVersion.go @@ -1,5 +1,5 @@ package goext -const GoextVersion = "0.0.511" +const GoextVersion = "0.0.512" -const GoextVersionTimestamp = "2024-09-15T18:22:07+0200" +const GoextVersionTimestamp = "2024-09-15T21:25:21+0200" diff --git a/gojson/encode.go b/gojson/encode.go index 3aa758e..f851b67 100644 --- a/gojson/encode.go +++ b/gojson/encode.go @@ -788,7 +788,7 @@ FieldLoop: if f.omitEmpty && isEmptyValue(fv) { continue - } else if opts.filter != nil && !matchesJSONFilter(f.jsonfilter, *opts.filter) { + } else if !matchesJSONFilter(f.jsonfilter, opts.filter) { continue } e.WriteByte(next) @@ -808,16 +808,20 @@ FieldLoop: } } -func matchesJSONFilter(filter jsonfilter, value string) bool { +func matchesJSONFilter(filter jsonfilter, value *string) bool { if len(filter) == 0 { - return true + return true // no filter in struct + } + + if value == nil || *value == "" { + return false // no filter set, but struct has filter, return false } if len(filter) == 1 && filter[0] == "-" { return false } - if filter.Contains(value) { + if filter.Contains(*value) { return true }