@@ -37,6 +37,26 @@ namespace DigitalRuby.IPBanCore
3737 /// </summary>
3838 public class IPBanFilter : IIPBanFilter
3939 {
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+
4060 private static readonly HashSet < string > ignoreListEntries =
4161 [
4262 "0.0.0.0" ,
@@ -123,18 +143,19 @@ public IPBanFilter(string value, string regexValue, IHttpRequestMaker httpReques
123143 List < string > entries = [ ] ;
124144
125145 // 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 ) )
127148 {
128149 string entryWithoutComment = entry ;
129- int pos = entryWithoutComment . IndexOf ( '?' ) ;
150+ int pos = entryWithoutComment . IndexOfAny ( ItemPiecesDelimitersLegacy ) ;
130151 if ( pos >= 0 )
131152 {
132153 entryWithoutComment = entryWithoutComment [ ..pos ] ;
133154 }
134155 entryWithoutComment = entryWithoutComment . Trim ( ) ;
135156
136157 // 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 ) )
138159 {
139160 entries . Add ( subEntry ) ;
140161 }
0 commit comments