Fix a bunch of bugs in parsing/formatting found by fuzzing

This commit is contained in:
Joshua Warner 2023-02-05 11:48:05 -08:00
parent acd446f6bd
commit 3fee0d3e8f
No known key found for this signature in database
GPG key ID: 89AD497003F93FDD
43 changed files with 593 additions and 70 deletions

View file

@ -106,12 +106,20 @@ impl<'a> Buf<'a> {
self.spaces_to_flush += count;
}
pub fn newline(&mut self) {
/// Only for use in emitting newlines in block strings, which don't follow the rule of
/// having at most two newlines in a row.
pub fn push_newline_literal(&mut self) {
self.spaces_to_flush = 0;
self.newlines_to_flush += 1;
self.beginning_of_line = true;
}
pub fn newline(&mut self) {
self.spaces_to_flush = 0;
self.newlines_to_flush = std::cmp::min(self.newlines_to_flush + 1, 2);
self.beginning_of_line = true;
}
/// Ensures the current buffer ends in a newline, if it didn't already.
/// Doesn't add a newline if the buffer already ends in one.
pub fn ensure_ends_with_newline(&mut self) {