File tree Expand file tree Collapse file tree 2 files changed +16
-6
lines changed
Statiq.Web.Hosting/Middleware Expand file tree Collapse file tree 2 files changed +16
-6
lines changed Original file line number Diff line number Diff line change @@ -34,7 +34,7 @@ public async Task InvokeAsync(HttpContext context)
3434
3535 foreach ( KeyValuePair < string , string > header in _customHeaders )
3636 {
37- context . Response . Headers . Append ( header . Key , header . Value ) ;
37+ context . Response . Headers . Append ( header . Key , header . Value ?? string . Empty ) ;
3838 }
3939 }
4040 }
Original file line number Diff line number Diff line change @@ -224,17 +224,27 @@ internal static void GetKeyValues(
224224 }
225225 }
226226
227- private static Dictionary < string , string > GetKeyValues ( IEnumerable < string > keysAndValues , string optionName )
227+ private static Dictionary < string , string > GetKeyValues (
228+ IEnumerable < string > keysAndValues ,
229+ string optionName )
228230 {
229231 Dictionary < string , string > dictionary = new Dictionary < string , string > ( ) ;
230232 foreach ( string keyAndValue in keysAndValues )
231233 {
232- string [ ] split = keyAndValue . Split ( '=' ) ;
233- if ( split . Length < 2 )
234+ int equalsLocation = keyAndValue . IndexOf ( "=" ) ;
235+ if ( equalsLocation == 0 )
236+ {
237+ throw new ArgumentException ( $ "Invalid { optionName } (no key): { keyAndValue } ") ;
238+ }
239+ if ( equalsLocation >= keyAndValue . Length - 1 )
240+ {
241+ throw new ArgumentException ( $ "Invalid { optionName } (no value): { keyAndValue } ") ;
242+ }
243+ if ( equalsLocation < 0 )
234244 {
235- throw new ArgumentException ( $ "Invalid { optionName } { keyAndValue } specified. ") ;
245+ throw new ArgumentException ( $ "Invalid { optionName } (no equals sign): { keyAndValue } ") ;
236246 }
237- dictionary [ split [ 0 ] . Trim ( ) . Trim ( ' \" ' ) ] = split [ 1 ] . Trim ( ) . Trim ( ' \" ' ) ;
247+ dictionary [ keyAndValue . Substring ( 0 , equalsLocation ) ] = keyAndValue . Substring ( equalsLocation + 1 ) ;
238248 }
239249 return dictionary ;
240250 }
You can’t perform that action at this time.
0 commit comments