Skip to content

Commit

Permalink
Merge branch 'fix/payload_key_with_dots' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
pentateu committed Apr 18, 2022
2 parents 66d845c + fd9f9b0 commit 013d7f6
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
7 changes: 7 additions & 0 deletions payload/payload.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
7 changes: 7 additions & 0 deletions payload/payload_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
})
})

0 comments on commit 013d7f6

Please sign in to comment.