From 18bfa1324203c423ccfb632899b4894862455248 Mon Sep 17 00:00:00 2001 From: Juan Carlos Galvis Date: Wed, 28 Jul 2021 12:15:37 -0500 Subject: [PATCH] fix index out of range, closes #40 --- getbycorrelid_test.go | 5 +++++ mqjms/MessageImpl.go | 6 ++---- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/getbycorrelid_test.go b/getbycorrelid_test.go index b3b13e8..88de46a 100644 --- a/getbycorrelid_test.go +++ b/getbycorrelid_test.go @@ -202,4 +202,9 @@ func TestCorrelIDParsing(t *testing.T) { msg.SetJMSCorrelationID(testCorrel) assert.Equal(t, testCorrel, msg.GetJMSCorrelationID()) + // Empty correlationID + testCorrel = "000000000000000000000000000000000000000000000000" + msg.SetJMSCorrelationID(testCorrel) + assert.Equal(t, "", msg.GetJMSCorrelationID()) + } diff --git a/mqjms/MessageImpl.go b/mqjms/MessageImpl.go index 2707a27..bf012ed 100644 --- a/mqjms/MessageImpl.go +++ b/mqjms/MessageImpl.go @@ -175,10 +175,8 @@ func (msg *MessageImpl) GetJMSCorrelationID() string { // Here we identify any padding zero bytes to trim off so that we can try // to turn it back into a string. realLength := len(correlIDBytes) - if realLength > 0 { - for correlIDBytes[realLength-1] == 0 { - realLength-- - } + for realLength > 0 && correlIDBytes[realLength-1] == 0 { + realLength-- } // Attempt to decode the content back into a string.