Skip to content

Commit

Permalink
Fix edge case when filesPayload message is nil (#116)
Browse files Browse the repository at this point in the history
* Fix edge case when filesPayload message is nil

* Update .gitignore

* PubNub SDK v6.0.2 release.

Co-authored-by: Client Engineering Bot <Client Engineering [email protected]>
  • Loading branch information
crimsonred and Client Engineering Bot authored Nov 29, 2021
1 parent 9f66c2d commit 15c9393
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 13 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,5 @@ vendor/golang.org/
# GitHub Actions #
##################
.github/.release

.vscode
11 changes: 8 additions & 3 deletions .pubnub.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
---
version: v6.0.1
changelog:
version: v6.0.2
changelog:
- date: 2021-11-24
version: v6.0.2
changes:
- type: bug
text: "Fix edge case in Fetch response when filesPayload message is nil."
-
changes:
-
Expand Down Expand Up @@ -680,7 +685,7 @@ sdks:
distribution-type: package
distribution-repository: GitHub release
package-name: Go
location: https://github.com/pubnub/go/releases/tag/v5.0.0
location: https://github.com/pubnub/go/releases/tag/v6.0.2
requires:
-
name: "Go"
Expand Down
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## v6.0.2
November 24 2021

#### Fixed
- Fix edge case in Fetch response when filesPayload message is nil.

## [v6.0.1](https://github.com/pubnub/go/releases/tag/v6.0.1)
October-13-2021

Expand Down
22 changes: 13 additions & 9 deletions files_common.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,18 +65,22 @@ func ParseFileInfo(filesPayload map[string]interface{}) (PNFileDetails, PNPublis

//"message":{"text":"test file"},"file":{"name":"test_file_upload_name_32899","id":"9076246e-5036-42af-b3a3-767b514c93c8"}}
if o, ok := filesPayload["file"]; ok {
data = o.(map[string]interface{})
if d, ok := data["id"]; ok {
resp.PNFile.ID = d.(string)
}
if d, ok := data["name"]; ok {
resp.PNFile.Name = d.(string)
if o != nil {
data = o.(map[string]interface{})
if d, ok := data["id"]; ok {
resp.PNFile.ID = d.(string)
}
if d, ok := data["name"]; ok {
resp.PNFile.Name = d.(string)
}
}
}
if m, ok := filesPayload["message"]; ok {
data = m.(map[string]interface{})
if d, ok := data["text"]; ok {
resp.PNMessage.Text = d.(string)
if m != nil {
data = m.(map[string]interface{})
if d, ok := data["text"]; ok {
resp.PNMessage.Text = d.(string)
}
}
}
return resp.PNFile, resp.PNMessage
Expand Down
28 changes: 28 additions & 0 deletions files_common_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package pubnub

import (
"testing"

"github.com/stretchr/testify/assert"
)

func TestParseFileInfo(t *testing.T) {
assert := assert.New(t)
resp := make(map[string]interface{})
resp["message"] = nil
resp["file"] = map[string]interface{}{"name": "test_file_upload_name_32899", "id": "9076246e-5036-42af-b3a3-767b514c93c8"}
f, m := ParseFileInfo(resp)
assert.Equal(f.ID, "9076246e-5036-42af-b3a3-767b514c93c8")
assert.Equal(m.Text, "")
}

func TestParseFileInfoNotNil(t *testing.T) {
assert := assert.New(t)
resp := make(map[string]interface{})
resp["message"] = map[string]interface{}{"text": "test file"}
resp["file"] = map[string]interface{}{"name": "test_file_upload_name_32899", "id": "9076246e-5036-42af-b3a3-767b514c93c8"}

f, m := ParseFileInfo(resp)
assert.Equal(f.ID, "9076246e-5036-42af-b3a3-767b514c93c8")
assert.Equal(m.Text, "test file")
}
2 changes: 1 addition & 1 deletion pubnub.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
// Default constants
const (
// Version :the version of the SDK
Version = "6.0.1"
Version = "6.0.2"
// MaxSequence for publish messages
MaxSequence = 65535
)
Expand Down

0 comments on commit 15c9393

Please sign in to comment.