Fix ''' ""''' formatting (#7485)

## Summary

`''' ""'''` is an edge case that was previously incorrectly formatted as
`""" """""`.

Fixes #7460

## Test Plan

Added regression test
This commit is contained in:
konsti
2023-09-18 12:28:15 +02:00
committed by GitHub
parent 70ea49bf72
commit c4d85d6fb6
3 changed files with 28 additions and 4 deletions

View File

@@ -543,10 +543,21 @@ fn preferred_quotes(
// `""` or `''`
chars.next();
if chars.peek().copied() == Some(configured_quote_char) {
// `"""` or `'''`
chars.next();
uses_triple_quotes = true;
match chars.peek().copied() {
Some(c) if c == configured_quote_char => {
// `"""` or `'''`
chars.next();
uses_triple_quotes = true;
break;
}
Some(_) => {}
None => {
// Handle `''' ""'''`. At this point we have consumed both
// double quotes, so on the next iteration the iterator is empty
// and we'd miss the string ending with a preferred quote
uses_triple_quotes = true;
break;
}
}
}
Some(_) => {
@@ -555,6 +566,7 @@ fn preferred_quotes(
None => {
// Trailing quote at the end of the comment
uses_triple_quotes = true;
break;
}
}
}