Skip to content

Commit 3650f93

Browse files
committed
fix: correctly check error on link
1 parent 90e57fa commit 3650f93

File tree

2 files changed

+29
-3
lines changed

2 files changed

+29
-3
lines changed

FirebaseAdmin/FirebaseAdmin.Tests/Messaging/MessageTest.cs

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1605,7 +1605,7 @@ public void WebpushNotificationWithLinkUrl()
16051605
}
16061606

16071607
[Fact]
1608-
public void WebpushNotificationWithInvalidLinkUrl()
1608+
public void WebpushNotificationWithInvalidHttpLinkUrl()
16091609
{
16101610
var message = new Message()
16111611
{
@@ -1627,6 +1627,29 @@ public void WebpushNotificationWithInvalidLinkUrl()
16271627
Assert.Throws<ArgumentException>(() => message.CopyAndValidate());
16281628
}
16291629

1630+
[Fact]
1631+
public void WebpushNotificationWithInvalidHttpsLinkUrl()
1632+
{
1633+
var message = new Message()
1634+
{
1635+
Topic = "test-topic",
1636+
Webpush = new WebpushConfig()
1637+
{
1638+
Notification = new WebpushNotification()
1639+
{
1640+
Title = "title",
1641+
Body = "body",
1642+
Icon = "icon",
1643+
},
1644+
FcmOptions = new WebpushFcmOptions()
1645+
{
1646+
Link = "https whatever",
1647+
},
1648+
},
1649+
};
1650+
Assert.Throws<ArgumentException>(() => message.CopyAndValidate());
1651+
}
1652+
16301653
private void AssertJsonEquals(JObject expected, Message actual)
16311654
{
16321655
var json = NewtonsoftJsonSerializer.Instance.Serialize(actual.CopyAndValidate());

FirebaseAdmin/FirebaseAdmin/Messaging/WebpushFcmOptions.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,12 @@ internal WebpushFcmOptions CopyAndValidate()
4040
Link = this.Link,
4141
};
4242

43-
if (copy.Link != null && Uri.IsWellFormedUriString(copy.Link, UriKind.Absolute) && !copy.Link.StartsWith("https"))
43+
if (copy.Link != null)
4444
{
45-
throw new ArgumentException("The link options should be a valid https url.");
45+
if (!Uri.IsWellFormedUriString(copy.Link, UriKind.Absolute) || !copy.Link.StartsWith("https"))
46+
{
47+
throw new ArgumentException("The link options should be a valid https url.");
48+
}
4649
}
4750

4851
return copy;

0 commit comments

Comments
 (0)