Fix possible misindent in block scalar.

This commit is contained in:
Ethiraric 2024-01-19 14:55:06 +01:00
parent b2aa95b4c1
commit 99d82be6a3
2 changed files with 16 additions and 7 deletions

View file

@ -681,7 +681,10 @@ impl<T: Iterator<Item = char>> Scanner<T> {
self.fetch_document_indicator(TokenType::DocumentEnd)?; self.fetch_document_indicator(TokenType::DocumentEnd)?;
self.skip_ws_to_eol(SkipTabs::Yes); self.skip_ws_to_eol(SkipTabs::Yes);
if !is_breakz(self.ch()) { if !is_breakz(self.ch()) {
return Err(ScanError::new(self.mark, "invalid content after document end marker")); return Err(ScanError::new(
self.mark,
"invalid content after document end marker",
));
} }
return Ok(()); return Ok(());
} }
@ -1690,7 +1693,18 @@ impl<T: Iterator<Item = char>> Scanner<T> {
} }
} }
*indent = max_indent.max((self.indent + 1) as usize).max(1); // In case a yaml looks like:
// ```yaml
// |
// foo
// bar
// ```
// We need to set the indent to 0 and not 1. In all other cases, the indent must be at
// least 1. When in the above example, `self.indent` will be set to -1.
*indent = max_indent.max((self.indent + 1) as usize);
if self.indent > 0 {
*indent = (*indent).max(1);
}
} }
fn fetch_flow_scalar(&mut self, single: bool) -> ScanResult { fn fetch_flow_scalar(&mut self, single: bool) -> ScanResult {

View file

@ -297,11 +297,6 @@ fn expected_events(expected_tree: &str) -> Vec<String> {
#[rustfmt::skip] #[rustfmt::skip]
static EXPECTED_FAILURES: &[&str] = &[ static EXPECTED_FAILURES: &[&str] = &[
// Bare document after end marker
"M7A3",
// Scalar marker on document start line
"DK3J",
"FP8R",
// Comments on nonempty lines need leading space // Comments on nonempty lines need leading space
"9JBA", "9JBA",
"CVW2", "CVW2",