This repository was archived by the owner on Oct 2, 2024. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +37
-1
lines changed
src/SerilogWeb.Classic/Classic
test/SerilogWeb.Classic.Tests Expand file tree Collapse file tree 2 files changed +37
-1
lines changed Original file line number Diff line number Diff line change @@ -89,7 +89,17 @@ internal SerilogWebClassicConfiguration Edit(Func<SerilogWebClassicConfiguration
89
89
/// <param name="value">Value of the pair</param>
90
90
internal string FilterPasswords ( string key , string value )
91
91
{
92
- if ( FilterPasswordsInFormData && FilteredKeywordsInFormData . Any ( keyword => key . IndexOf ( keyword , StringComparison . OrdinalIgnoreCase ) != - 1 ) )
92
+ if ( ! FilterPasswordsInFormData )
93
+ {
94
+ return value ;
95
+ }
96
+
97
+ if ( key == null )
98
+ {
99
+ return value ;
100
+ }
101
+
102
+ if ( FilteredKeywordsInFormData . Any ( keyword => key . IndexOf ( keyword , StringComparison . OrdinalIgnoreCase ) != - 1 ) )
93
103
{
94
104
return "********" ;
95
105
}
Original file line number Diff line number Diff line change @@ -363,6 +363,32 @@ public void PasswordBlackListCanBeCustomized()
363
363
Assert . Equal ( expectedLoggedData . ToString ( ) , formDataProperty . ToString ( ) ) ;
364
364
}
365
365
366
+ [ Fact ]
367
+ public void LogPostedFormDataHandlesNullKeyWhenFiltered ( )
368
+ {
369
+ var formData = new NameValueCollection
370
+ {
371
+ { "Foo" , "Bar" } ,
372
+ { "Qux" , "Baz" } ,
373
+ { null , "" }
374
+ } ;
375
+
376
+ SerilogWebClassic . Configure ( cfg => cfg
377
+ . EnableFormDataLogging ( forms => forms
378
+ . FilterKeywords ( new List < string >
379
+ {
380
+ "NA"
381
+ } ) )
382
+ ) ;
383
+
384
+ TestContext . SimulateForm ( formData ) ;
385
+
386
+ var formDataProperty = LastEvent . Properties [ "FormData" ] ;
387
+ Assert . NotNull ( formDataProperty ) ;
388
+ var expected = formData . ToSerilogNameValuePropertySequence ( ) ;
389
+ Assert . Equal ( expected . ToString ( ) , formDataProperty . ToString ( ) ) ;
390
+ }
391
+
366
392
[ Fact ]
367
393
public void EnableDisable ( )
368
394
{
You can’t perform that action at this time.
0 commit comments