File tree 2 files changed +28
-1
lines changed 2 files changed +28
-1
lines changed Original file line number Diff line number Diff line change @@ -1800,7 +1800,10 @@ impl<T: Iterator<Item = char>> Scanner<T> {
1800
1800
while !self . buffer . is_empty ( ) && self . mark . col < indent && self . ch ( ) == ' ' {
1801
1801
self . skip_blank ( ) ;
1802
1802
}
1803
- if !( !self . buffer . is_empty ( ) && self . mark . col < indent && self . ch ( ) == ' ' ) {
1803
+ // If we reached our indent, we can break. We must also break if we have
1804
+ // reached content or EOF; that is, the buffer is not empty and the next
1805
+ // character is not a space.
1806
+ if self . mark . col == indent || ( !self . buffer . is_empty ( ) && self . ch ( ) != ' ' ) {
1804
1807
break ;
1805
1808
}
1806
1809
}
Original file line number Diff line number Diff line change @@ -260,6 +260,30 @@ foobar";
260
260
) ;
261
261
}
262
262
263
+ #[ test]
264
+ fn test_large_block_scalar_indent ( ) {
265
+ // https://github.com/Ethiraric/yaml-rust2/issues/29
266
+ // Tests the `loop` fallback of `skip_block_scalar_indent`. The indent in the YAML string must
267
+ // be greater than `BUFFER_LEN - 2`. The second line is further indented with spaces, and the
268
+ // resulting string should be "a\n b".
269
+ let s = "
270
+ a: |-
271
+ a
272
+ b
273
+ " ;
274
+
275
+ let doc = & YamlLoader :: load_from_str ( s) . unwrap ( ) [ 0 ] ;
276
+ let Yaml :: Hash ( map) = doc else {
277
+ dbg ! ( doc) ;
278
+ panic ! ( )
279
+ } ;
280
+ assert_eq ! ( map. len( ) , 1 ) ;
281
+ assert_eq ! (
282
+ map. get( & Yaml :: String ( "a" . to_string( ) ) ) ,
283
+ Some ( & Yaml :: String ( String :: from( "a\n b" ) ) )
284
+ ) ;
285
+ }
286
+
263
287
#[ test]
264
288
fn test_bad_docstart ( ) {
265
289
assert ! ( YamlLoader :: load_from_str( "---This used to cause an infinite loop" ) . is_ok( ) ) ;
You can’t perform that action at this time.
0 commit comments