Skip to content

Commit 4e25731

Browse files
committed
Changed way for checking analytics label
1 parent 025f233 commit 4e25731

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

FirebaseAdmin/FirebaseAdmin/Messaging/Util/AnalyticsLabelChecker.cs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
using System;
2+
using System.Collections.Generic;
3+
using System.Collections.Immutable;
4+
using System.Linq;
25
using System.Text.RegularExpressions;
36

47
namespace FirebaseAdmin.Messaging.Util
@@ -8,7 +11,7 @@ namespace FirebaseAdmin.Messaging.Util
811
/// </summary>
912
public static class AnalyticsLabelChecker
1013
{
11-
private static string pattern = "^[a-zA-Z0-9-_.~%]{0,50}$";
14+
private static ImmutableHashSet<char> alowedChars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-~%".ToCharArray().ToImmutableHashSet();
1215

1316
/// <summary>
1417
/// Checks anytytics labels an throw if not valid.
@@ -17,10 +20,18 @@ public static class AnalyticsLabelChecker
1720
/// <param name="analyticsLabel">Analytics label.</param>
1821
public static void CheckAnalyticsLabelOrThrow(string analyticsLabel)
1922
{
20-
if (!Regex.IsMatch(analyticsLabel, pattern))
23+
if (analyticsLabel.Length > 50)
2124
{
2225
throw new ArgumentException("Analytics label must have format matching'^[a-zA-Z0-9-_.~%]{1,50}$");
2326
}
27+
28+
foreach (var character in analyticsLabel)
29+
{
30+
if (!alowedChars.Contains(character))
31+
{
32+
throw new ArgumentException("Analytics label must have format matching'^[a-zA-Z0-9-_.~%]{1,50}$");
33+
}
34+
}
2435
}
2536
}
2637
}

0 commit comments

Comments
 (0)