From fd9f9b006391316db68ba1fe5404f22d5e37e5bd Mon Sep 17 00:00:00 2001 From: Rafael Almeida Date: Mon, 18 Apr 2022 14:40:16 +1200 Subject: [PATCH] fix payload for map keys with "." dots --- payload/payload.go | 7 +++++++ payload/payload_test.go | 7 +++++++ 2 files changed, 14 insertions(+) diff --git a/payload/payload.go b/payload/payload.go index 802221ac..1bf6b6e8 100644 --- a/payload/payload.go +++ b/payload/payload.go @@ -470,6 +470,13 @@ func splitIndex(s string) (key string, index int) { } func (p *RawPayload) Get(s string, defaultValue ...interface{}) moleculer.Payload { + if _, ok := p.mapGet(s); ok { + if defaultValue != nil { + return p.getKey(s, defaultValue...) + } + return p.getKey(s) + } + //check if is a path of key if isPath(s) { if defaultValue != nil { diff --git a/payload/payload_test.go b/payload/payload_test.go index 3d0c6f91..72acd735 100644 --- a/payload/payload_test.go +++ b/payload/payload_test.go @@ -395,4 +395,11 @@ var _ = Describe("Payload", func() { Expect(p.Get("address.options[10].label").Exists()).Should(BeFalse()) }) + + It("should deal field paths name.subname...", func() { + p := New(M{ + "address.street": "jonny ave", + }) + Expect(p.Get("address.street").String()).Should(Equal("jonny ave")) + }) })