File tree Expand file tree Collapse file tree 1 file changed +13
-2
lines changed
FirebaseAdmin/FirebaseAdmin/Messaging/Util Expand file tree Collapse file tree 1 file changed +13
-2
lines changed Original file line number Diff line number Diff line change 1
1
using System ;
2
+ using System . Collections . Generic ;
3
+ using System . Collections . Immutable ;
4
+ using System . Linq ;
2
5
using System . Text . RegularExpressions ;
3
6
4
7
namespace FirebaseAdmin . Messaging . Util
@@ -8,7 +11,7 @@ namespace FirebaseAdmin.Messaging.Util
8
11
/// </summary>
9
12
public static class AnalyticsLabelChecker
10
13
{
11
- private static string pattern = "^[a-zA-Z0-9-_.~%]{0,50}$" ;
14
+ private static ImmutableHashSet < char > alowedChars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-~%" . ToCharArray ( ) . ToImmutableHashSet ( ) ;
12
15
13
16
/// <summary>
14
17
/// Checks anytytics labels an throw if not valid.
@@ -17,10 +20,18 @@ public static class AnalyticsLabelChecker
17
20
/// <param name="analyticsLabel">Analytics label.</param>
18
21
public static void CheckAnalyticsLabelOrThrow ( string analyticsLabel )
19
22
{
20
- if ( ! Regex . IsMatch ( analyticsLabel , pattern ) )
23
+ if ( analyticsLabel . Length > 50 )
21
24
{
22
25
throw new ArgumentException ( "Analytics label must have format matching'^[a-zA-Z0-9-_.~%]{1,50}$" ) ;
23
26
}
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
+ }
24
35
}
25
36
}
26
37
}
You can’t perform that action at this time.
0 commit comments