@@ -665,7 +665,10 @@ private void Read(string configContent)
665665 break ;
666666
667667 case var _ when Settings . KeyMatcher . IsMatch ( lineRaw ) :
668- ReadKeyAndValue ( ref currentSection , ref currentLine , lineRaw , lineNumber ) ;
668+ if ( ! Settings . MultiLineValues . HasFlag ( MultiLineValues . NotAllowed ) && IsKeyLikeArrayValue ( currentLine ? . Content , lineRaw ) )
669+ ReadKeyAndValue ( ref currentSection , ref currentLine , lineRaw , lineNumber , append : true , forceIncludeKey : true ) ;
670+ else
671+ ReadKeyAndValue ( ref currentSection , ref currentLine , lineRaw , lineNumber ) ;
669672 break ;
670673
671674 // Multi-line + allow value-less option on
@@ -697,6 +700,21 @@ private void Read(string configContent)
697700 sections . Add ( currentSection . SectionName , currentSection ) ;
698701 }
699702
703+ private bool IsKeyLikeArrayValue ( string currentLine , string lineRaw )
704+ {
705+ if ( string . IsNullOrWhiteSpace ( currentLine ) || string . IsNullOrWhiteSpace ( lineRaw ) )
706+ return false ;
707+
708+ var lastLine = currentLine ? . Split ( new string [ ] { Settings . NewLine } , StringSplitOptions . None ) ? . LastOrDefault ( ) ;
709+ var prevLineMatch = Settings . ArrayStartMatcher . Match ( lastLine ) ;
710+ var curLineMatch = Settings . ArrayStartMatcher . Match ( lineRaw ) ;
711+
712+ if ( ! prevLineMatch . Success || ! curLineMatch . Success )
713+ return false ;
714+
715+ return prevLineMatch . Groups [ 0 ] . Value . Length == curLineMatch . Groups [ 0 ] . Value . Length ;
716+ }
717+
700718 /// <summary>
701719 /// Reads the valueless key.
702720 /// </summary>
@@ -726,9 +744,11 @@ private void AppendValueToKey(ref ConfigSection currentSection, ref ConfigLine c
726744 {
727745 if ( MultiLineValues . NotAllowed == Settings . MultiLineValues ||
728746 Settings . MultiLineValues . HasFlag ( MultiLineValues . NotAllowed ) )
747+ {
729748 throw new ConfigParserException (
730749 "Multi-line values are explicitly disallowed by parser settings. Please consider changing them." ,
731750 lineNumber ) ;
751+ }
732752
733753 ReadKeyAndValue ( ref currentSection , ref currentLine , lineRaw , lineNumber , true ) ;
734754 }
@@ -745,7 +765,7 @@ private void AppendValueToKey(ref ConfigSection currentSection, ref ConfigLine c
745765 /// or</exception>
746766 /// <exception cref="NotImplementedException"></exception>
747767 private void ReadKeyAndValue ( ref ConfigSection currentSection , ref ConfigLine currentLine , string lineRaw ,
748- int lineNumber , bool append = false )
768+ int lineNumber , bool append = false , bool forceIncludeKey = false )
749769 {
750770 if ( null != currentLine && ! append )
751771 BackupCurrentLine ( ref currentSection , ref currentLine , lineNumber ) ;
@@ -758,7 +778,8 @@ private void ReadKeyAndValue(ref ConfigSection currentSection, ref ConfigLine cu
758778 var separator = ( string . IsNullOrWhiteSpace ( keyMatch . Groups [ "separator" ] ? . Value ) )
759779 ? Settings . KeyValueSeparator
760780 : keyMatch . Groups [ "separator" ] ? . Value ;
761- if ( keyMatch . Success && keyMatch . Captures . Count > 0 )
781+
782+ if ( ! forceIncludeKey && keyMatch . Success && keyMatch . Captures . Count > 0 )
762783 lineRaw = lineRaw . Substring ( keyMatch . Captures [ 0 ] . Value . Length ) ;
763784
764785 var valueMatch = Settings . ValueMatcher . Match ( lineRaw ) ;
0 commit comments