@@ -476,7 +476,7 @@ private string DecipherUnicodeEscapeSequence(string unicodeString, bool fourDigi
476
476
default :
477
477
if ( allowNewline && escapedChar . IsNewline ( ) )
478
478
return null ;
479
- throw new InvalidTomlEscapeException ( _lineNumber , $ "\\ { escapedChar } ") ;
479
+ throw new InvalidTomlEscapeException ( _lineNumber , $ "\\ { ( char ) escapedChar } ") ;
480
480
}
481
481
482
482
return toAppend ;
@@ -604,6 +604,43 @@ private TomlValue ReadMultiLineBasicString(TomletStringReader reader)
604
604
if ( escapeMode )
605
605
{
606
606
escapeMode = false ;
607
+
608
+ //If the escaped char is whitespace, and there's no other non-whitespace on this line, we skip all whitespace until the next non-whitespace char.
609
+ if ( nextChar . IsWhitespace ( ) || nextChar . IsNewline ( ) )
610
+ {
611
+ //Check that everything else on this line is whitespace
612
+ var backtrack = 0 ;
613
+ var skipWhitespace = false ;
614
+ while ( reader . TryPeek ( out var nextCharOnLine ) )
615
+ {
616
+ backtrack ++ ;
617
+ reader . Read ( ) ;
618
+
619
+ if ( nextCharOnLine . IsNewline ( ) )
620
+ {
621
+ skipWhitespace = true ;
622
+ break ;
623
+ }
624
+
625
+ if ( ! nextCharOnLine . IsWhitespace ( ) )
626
+ {
627
+ //Backslash-whitespace but then non-whitespace char before newline, this is invalid, we can break here and let HandleEscapedChar deal with it
628
+ break ;
629
+ }
630
+ }
631
+
632
+ //Return back to where we were
633
+ reader . Backtrack ( backtrack ) ;
634
+
635
+ if ( skipWhitespace )
636
+ {
637
+ _lineNumber += reader . SkipAnyNewlineOrWhitespace ( ) ;
638
+ continue ; //The main while loop
639
+ }
640
+
641
+ //Otherwise we drop down to HandleEscapedChar, which will throw due to the whitespace
642
+ }
643
+
607
644
var toAppend = HandleEscapedChar ( nextChar , out fourDigitUnicodeMode , out eightDigitUnicodeMode , true ) ;
608
645
609
646
if ( toAppend . HasValue )
@@ -618,7 +655,7 @@ private TomlValue ReadMultiLineBasicString(TomletStringReader reader)
618
655
_lineNumber ++ ;
619
656
620
657
//Escaped newline indicates we skip this newline and any whitespace at the start of the next line
621
- reader . SkipAnyNewlineOrWhitespace ( ) ;
658
+ _lineNumber += reader . SkipAnyNewlineOrWhitespace ( ) ;
622
659
}
623
660
624
661
continue ;
0 commit comments