diff --git a/.gitignore b/.gitignore index 2268b7a1..38ac29fd 100644 --- a/.gitignore +++ b/.gitignore @@ -31,3 +31,5 @@ vendor/golang.org/ # GitHub Actions # ################## .github/.release + +.vscode diff --git a/.pubnub.yml b/.pubnub.yml index 45215ded..90516916 100644 --- a/.pubnub.yml +++ b/.pubnub.yml @@ -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: - @@ -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" diff --git a/CHANGELOG.md b/CHANGELOG.md index afdd39c1..1f350993 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/files_common.go b/files_common.go index 01ce7c9e..93a6d0fe 100644 --- a/files_common.go +++ b/files_common.go @@ -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 diff --git a/files_common_test.go b/files_common_test.go new file mode 100644 index 00000000..73745e8b --- /dev/null +++ b/files_common_test.go @@ -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") +} diff --git a/pubnub.go b/pubnub.go index 910eba93..466da5cc 100644 --- a/pubnub.go +++ b/pubnub.go @@ -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 )