@@ -16,6 +16,17 @@ public class AllPrimitivesClass
1616 public string ? StringValue { get ; set ; }
1717}
1818
19+ /// <summary>
20+ /// Class for testing multiple multi-line string properties.
21+ /// </summary>
22+ public class MultiStringClass
23+ {
24+ public string ? FirstText { get ; set ; }
25+ public string ? SecondText { get ; set ; }
26+ public string ? ThirdText { get ; set ; }
27+ public int Value { get ; set ; }
28+ }
29+
1930/// <summary>
2031/// Class for testing special float values.
2132/// </summary>
@@ -493,6 +504,42 @@ public void RoundtripMultilineString_PreservesContent()
493504 Assert . Equal ( original . Name , deserialized . Name ) ;
494505 }
495506
507+ [ Fact ]
508+ public void SerializeMultipleBlockScalars_NoExtraBlankLines ( )
509+ {
510+ // Arrange - Object with multiple multi-line string properties
511+ var original = new MultiStringClass
512+ {
513+ FirstText = "First line\n Second line\n " ,
514+ SecondText = "Another first line\n Another second line\n " ,
515+ ThirdText = "Third property line 1\n Third property line 2\n " ,
516+ Value = 42
517+ } ;
518+
519+ // Act
520+ var yaml = YamlSerializer . Serialize ( original , TestSerializerContext . Default . MultiStringClass ) ;
521+
522+ // Assert - Should use | (clip) chomping for strings ending with newline
523+ Assert . Contains ( "first-text: |" , yaml ) ;
524+ Assert . Contains ( "second-text: |" , yaml ) ;
525+ Assert . Contains ( "third-text: |" , yaml ) ;
526+
527+ // Verify no extra blank lines between properties
528+ // Each block scalar content ends with a newline, then the next property should start
529+ // immediately on the next line without an extra blank line
530+ Assert . DoesNotContain ( "\n \n second-text:" , yaml ) ;
531+ Assert . DoesNotContain ( "\n \n third-text:" , yaml ) ;
532+ Assert . DoesNotContain ( "\n \n value:" , yaml ) ;
533+
534+ // Verify roundtrip
535+ var deserialized = YamlSerializer . Deserialize ( yaml , TestSerializerContext . Default . MultiStringClass ) ;
536+ Assert . NotNull ( deserialized ) ;
537+ Assert . Equal ( original . FirstText , deserialized . FirstText ) ;
538+ Assert . Equal ( original . SecondText , deserialized . SecondText ) ;
539+ Assert . Equal ( original . ThirdText , deserialized . ThirdText ) ;
540+ Assert . Equal ( original . Value , deserialized . Value ) ;
541+ }
542+
496543 [ Fact ]
497544 public void DeserializeMultilinePlainScalar_FoldsToSingleLine ( )
498545 {
0 commit comments