Skip to content

Commit 51b56db

Browse files
committed
Do not throw on invalid replyTo address
1 parent c9e36dc commit 51b56db

File tree

4 files changed

+48
-10
lines changed

4 files changed

+48
-10
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: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,7 @@ public void TestPersistentPropertyChangesDeliveryMode_PersistentFalseDelivery1()
8282
public void TestNullableProperties_CanWrite(
8383
[Values(null, "cluster1")] string clusterId,
8484
[Values(null, "732E39DC-AF56-46E8-B8A9-079C4B991B2E")] string correlationId,
85-
[Values(null, "7D221C7E-1788-4D11-9CA5-AC41425047CF")] string messageId
86-
)
85+
[Values(null, "7D221C7E-1788-4D11-9CA5-AC41425047CF")] string messageId)
8786
{
8887
// Arrange
8988
var subject = new Framing.BasicProperties
@@ -120,5 +119,34 @@ public void TestNullableProperties_CanWrite(
120119
Assert.AreEqual(isCorrelationIdPresent, propertiesFromStream.IsCorrelationIdPresent());
121120
Assert.AreEqual(isMessageIdPresent, propertiesFromStream.IsMessageIdPresent());
122121
}
122+
123+
[Test]
124+
public void TestProperties_ReplyTo([Values(null, "foo_1", "fanout://name/key")] string replyTo)
125+
{
126+
// Arrange
127+
var subject = new Framing.BasicProperties
128+
{
129+
130+
// Act
131+
ReplyTo = replyTo,
132+
};
133+
134+
// Assert
135+
bool isReplyToPresent = replyTo != null;
136+
string replyToAddress = PublicationAddress.Parse(replyTo)?.ToString();
137+
Assert.AreEqual(isReplyToPresent, subject.IsReplyToPresent());
138+
139+
var writer = new Impl.ContentHeaderPropertyWriter(new byte[1024]);
140+
subject.WritePropertiesTo(ref writer);
141+
142+
// Read from Stream
143+
var propertiesFromStream = new Framing.BasicProperties();
144+
var reader = new Impl.ContentHeaderPropertyReader(writer.Memory.Slice(0, writer.Offset));
145+
propertiesFromStream.ReadPropertiesFrom(ref reader);
146+
147+
Assert.AreEqual(replyTo, propertiesFromStream.ReplyTo);
148+
Assert.AreEqual(isReplyToPresent, propertiesFromStream.IsReplyToPresent());
149+
Assert.AreEqual(replyToAddress, propertiesFromStream.ReplyToAddress?.ToString());
150+
}
123151
}
124152
}

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)