Skip to content

Commit e7d264a

Browse files
authored
Merge pull request #41 from bancolombia/fix/get-empty-correlation-id
Fix index out of range, closes #40
2 parents 6b0c90f + 18bfa13 commit e7d264a

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

getbycorrelid_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,4 +202,9 @@ func TestCorrelIDParsing(t *testing.T) {
202202
msg.SetJMSCorrelationID(testCorrel)
203203
assert.Equal(t, testCorrel, msg.GetJMSCorrelationID())
204204

205+
// Empty correlationID
206+
testCorrel = "000000000000000000000000000000000000000000000000"
207+
msg.SetJMSCorrelationID(testCorrel)
208+
assert.Equal(t, "", msg.GetJMSCorrelationID())
209+
205210
}

mqjms/MessageImpl.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -175,10 +175,8 @@ func (msg *MessageImpl) GetJMSCorrelationID() string {
175175
// Here we identify any padding zero bytes to trim off so that we can try
176176
// to turn it back into a string.
177177
realLength := len(correlIDBytes)
178-
if realLength > 0 {
179-
for correlIDBytes[realLength-1] == 0 {
180-
realLength--
181-
}
178+
for realLength > 0 && correlIDBytes[realLength-1] == 0 {
179+
realLength--
182180
}
183181

184182
// Attempt to decode the content back into a string.

0 commit comments

Comments
 (0)