File tree Expand file tree Collapse file tree
compiler/rustc_errors/src/markdown Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -220,7 +220,7 @@ fn parse_codeblock(buf: &[u8]) -> Parsed<'_> {
220220 let mut found = None ;
221221 for idx in ( 0 ..working. len ( ) ) . filter ( |idx| working[ * idx..] . starts_with ( & end_pat) ) {
222222 let ( eol_txt, rest) = parse_to_newline ( & working[ ( idx + end_pat. len ( ) ) ..] ) ;
223- if ! eol_txt. iter ( ) . any ( u8:: is_ascii_whitespace) {
223+ if eol_txt. iter ( ) . all ( u8:: is_ascii_whitespace) {
224224 found = Some ( ( & working[ ..idx] , rest) ) ;
225225 break ;
226226 }
Original file line number Diff line number Diff line change @@ -364,3 +364,16 @@ fn test_snake_case() {
364364 let res = entrypoint ( SNAKE_CASE ) ;
365365 assert_eq ! ( res, expected) ;
366366}
367+
368+ #[ test]
369+ fn test_codeblock_trailing_whitespace ( ) {
370+ let buf = "```rust\n code\n ``` \n rest" ;
371+ let ( t, r) = parse_codeblock ( buf. as_bytes ( ) ) ;
372+ assert_eq ! ( t, MdTree :: CodeBlock { txt: "code" , lang: Some ( "rust" ) } ) ;
373+ assert_eq ! ( r, b"\n rest" ) ;
374+
375+ let buf = "```rust\n code\n ```abc\n rest" ;
376+ let ( t, r) = parse_codeblock ( buf. as_bytes ( ) ) ;
377+ assert_eq ! ( t, MdTree :: CodeBlock { txt: "code\n ```abc\n rest" , lang: Some ( "rust" ) } ) ;
378+ assert_eq ! ( r, b"" ) ;
379+ }
You can’t perform that action at this time.
0 commit comments