@@ -18,27 +18,33 @@ internal static class ConfigFileParser
1818 CommentRegex = CommentRegex ,
1919 AllowDuplicateKeys = true ,
2020 AllowDuplicateSections = true ,
21- OverrideDuplicateKeys = true
21+ OverrideDuplicateKeys = true ,
22+ SkipInvalidLines = true ,
23+ ThrowExceptionsOnError = false
2224 } ;
2325
2426 public static ConfigFile Parse ( string filePath , IFileSystem fileSystem )
2527 {
28+ var directory = fileSystem . Path . GetDirectoryName ( filePath ) ;
29+
30+ ArgumentNullException . ThrowIfNull ( directory ) ;
31+
2632 var parser = new FileIniDataParser ( new IniDataParser ( Configuration ) ) ;
2733
2834 using var stream = fileSystem . File . OpenRead ( filePath ) ;
2935 using var streamReader = new StreamReader ( stream ) ;
3036 var configData = parser . ReadData ( streamReader ) ;
3137
32- var directory = fileSystem . Path . GetDirectoryName ( filePath ) ;
33-
34- ArgumentNullException . ThrowIfNull ( directory ) ;
35-
3638 var sections = new List < Section > ( ) ;
37- foreach ( var section in configData . Sections )
39+ if ( configData is not null )
3840 {
39- sections . Add ( new Section ( section , directory ) ) ;
41+ sections . AddRange ( configData . Sections . Select ( s => new Section ( s , directory ) ) ) ;
4042 }
4143
42- return new ConfigFile { IsRoot = configData . Global [ "root" ] == "true" , Sections = sections } ;
44+ return new ConfigFile
45+ {
46+ IsRoot = configData ? . Global [ "root" ] == "true" ,
47+ Sections = sections
48+ } ;
4349 }
4450}
0 commit comments