@@ -37,6 +37,26 @@ namespace DigitalRuby.IPBanCore
37
37
/// </summary>
38
38
public class IPBanFilter : IIPBanFilter
39
39
{
40
+ /// <summary>
41
+ /// Delimiter for each item in a filter string
42
+ /// </summary>
43
+ public const char ItemDelimiter = ',' ;
44
+
45
+ /// <summary>
46
+ /// Item pieces delimiters including the legacy ? and the current |
47
+ /// </summary>
48
+ public static readonly char [ ] ItemPiecesDelimitersLegacy = [ '?' , '|' ] ;
49
+
50
+ /// <summary>
51
+ /// Item pieces delimiter |
52
+ /// </summary>
53
+ public const char ItemPiecesDelimiter = '|' ;
54
+
55
+ /// <summary>
56
+ /// Used if multiple ips in one entry (rare)
57
+ /// </summary>
58
+ public const char SubEntryDelimiter = ';' ;
59
+
40
60
private static readonly HashSet < string > ignoreListEntries =
41
61
[
42
62
"0.0.0.0" ,
@@ -123,18 +143,19 @@ public IPBanFilter(string value, string regexValue, IHttpRequestMaker httpReques
123
143
List < string > entries = [ ] ;
124
144
125
145
// primary entries (entry?timestamp?notes) are delimited by comma
126
- foreach ( string entry in value . Split ( ',' , StringSplitOptions . RemoveEmptyEntries | StringSplitOptions . TrimEntries ) )
146
+ // | can be used as a sub delimiter instead of ? mark
147
+ foreach ( string entry in value . Split ( ItemDelimiter , StringSplitOptions . RemoveEmptyEntries | StringSplitOptions . TrimEntries ) )
127
148
{
128
149
string entryWithoutComment = entry ;
129
- int pos = entryWithoutComment . IndexOf ( '?' ) ;
150
+ int pos = entryWithoutComment . IndexOfAny ( ItemPiecesDelimitersLegacy ) ;
130
151
if ( pos >= 0 )
131
152
{
132
153
entryWithoutComment = entryWithoutComment [ ..pos ] ;
133
154
}
134
155
entryWithoutComment = entryWithoutComment . Trim ( ) ;
135
156
136
157
// sub entries (multiple ip addresses) are delimited by semi-colon
137
- foreach ( string subEntry in entryWithoutComment . Split ( ';' , StringSplitOptions . RemoveEmptyEntries | StringSplitOptions . TrimEntries ) )
158
+ foreach ( string subEntry in entryWithoutComment . Split ( SubEntryDelimiter , StringSplitOptions . RemoveEmptyEntries | StringSplitOptions . TrimEntries ) )
138
159
{
139
160
entries . Add ( subEntry ) ;
140
161
}
0 commit comments