Skip to content

Commit 7ed249c

Browse files
Merge pull request #828 from ig-sinicyn/feature/message-properties-do-not-throw
Do not throw on invalid ReplyTo address
2 parents c9e36dc + fb1a62c commit 7ed249c

File tree

4 files changed

+49
-8
lines changed

4 files changed

+49
-8
lines changed

projects/RabbitMQ.Client/client/api/PublicationAddress.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,14 @@ public PublicationAddress(string exchangeType, string exchangeName, string routi
106106
/// </summary>
107107
public static PublicationAddress Parse(string uriLikeString)
108108
{
109+
// Callers such as IBasicProperties.ReplyToAddress
110+
// expect null result for invalid input.
111+
// The regex.Match() throws on null arguments so we perform explicit check here
112+
if (uriLikeString == null)
113+
{
114+
return null;
115+
}
116+
109117
Match match = PSEUDO_URI_PARSER.Match(uriLikeString);
110118
if (match.Success)
111119
{

projects/Unit/TestBasicProperties.cs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,5 +120,36 @@ public void TestNullableProperties_CanWrite(
120120
Assert.AreEqual(isCorrelationIdPresent, propertiesFromStream.IsCorrelationIdPresent());
121121
Assert.AreEqual(isMessageIdPresent, propertiesFromStream.IsMessageIdPresent());
122122
}
123+
124+
[Test]
125+
public void TestProperties_ReplyTo(
126+
[Values(null, "foo_1", "fanout://name/key")] string replyTo
127+
)
128+
{
129+
// Arrange
130+
var subject = new Framing.BasicProperties
131+
{
132+
133+
// Act
134+
ReplyTo = replyTo,
135+
};
136+
137+
// Assert
138+
bool isReplyToPresent = replyTo != null;
139+
string replyToAddress = PublicationAddress.Parse(replyTo)?.ToString();
140+
Assert.AreEqual(isReplyToPresent, subject.IsReplyToPresent());
141+
142+
var writer = new Impl.ContentHeaderPropertyWriter(new byte[1024]);
143+
subject.WritePropertiesTo(ref writer);
144+
145+
// Read from Stream
146+
var propertiesFromStream = new Framing.BasicProperties();
147+
var reader = new Impl.ContentHeaderPropertyReader(writer.Memory.Slice(0, writer.Offset));
148+
propertiesFromStream.ReadPropertiesFrom(ref reader);
149+
150+
Assert.AreEqual(replyTo, propertiesFromStream.ReplyTo);
151+
Assert.AreEqual(isReplyToPresent, propertiesFromStream.IsReplyToPresent());
152+
Assert.AreEqual(replyToAddress, propertiesFromStream.ReplyToAddress?.ToString());
153+
}
123154
}
124155
}

projects/Unit/TestPropertiesClone.cs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,10 @@ private void TestBasicPropertiesClone(BasicProperties bp)
6868
bp.ContentType = "foo_1";
6969
bp.ContentEncoding = "foo_2";
7070
bp.Headers = new Dictionary<string, object>
71-
{
72-
{ "foo_3", "foo_4" },
73-
{ "foo_5", "foo_6" }
74-
};
71+
{
72+
{ "foo_3", "foo_4" },
73+
{ "foo_5", "foo_6" }
74+
};
7575
bp.DeliveryMode = 2;
7676
// Persistent also changes DeliveryMode's value to 2
7777
bp.Persistent = true;
@@ -123,6 +123,7 @@ private void TestBasicPropertiesClone(BasicProperties bp)
123123
Assert.AreEqual(12, bpClone.Priority);
124124
Assert.AreEqual("foo_7", bpClone.CorrelationId);
125125
Assert.AreEqual("foo_8", bpClone.ReplyTo);
126+
Assert.AreEqual(null, bpClone.ReplyToAddress);
126127
Assert.AreEqual("foo_9", bpClone.Expiration);
127128
Assert.AreEqual("foo_10", bpClone.MessageId);
128129
Assert.AreEqual(new AmqpTimestamp(123), bpClone.Timestamp);
@@ -141,10 +142,10 @@ private void TestBasicPropertiesNoneClone(BasicProperties bp)
141142
bp.ContentType = "foo_1";
142143
bp.ContentEncoding = "foo_2";
143144
bp.Headers = new Dictionary<string, object>
144-
{
145-
{ "foo_3", "foo_4" },
146-
{ "foo_5", "foo_6" }
147-
};
145+
{
146+
{ "foo_3", "foo_4" },
147+
{ "foo_5", "foo_6" }
148+
};
148149
bp.DeliveryMode = 2;
149150
// Persistent also changes DeliveryMode's value to 2
150151
bp.Persistent = true;

projects/Unit/TestPublicationAddress.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ public void TestParseOk()
5959
[Test]
6060
public void TestParseFail()
6161
{
62+
Assert.IsNull(PublicationAddress.Parse(null));
6263
Assert.IsNull(PublicationAddress.Parse("not a valid uri"));
6364
}
6465

0 commit comments

Comments
 (0)