Fix “not a char boundary” error with Unicode in extract_quote (#497)

This commit is contained in:
Anders Kaseorg 2022-10-28 18:59:12 -04:00 committed by GitHub
parent 782a90b584
commit f260b873b6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 3 additions and 11 deletions

View File

@ -248,17 +248,9 @@ const VALID_ESCAPE_SEQUENCES: &[char; 23] = &[
/// Return the quotation markers used for a String token.
fn extract_quote(text: &str) -> &str {
if text.len() >= 3 {
let triple = &text[text.len() - 3..];
if triple == "'''" || triple == "\"\"\"" {
return triple;
}
}
if !text.is_empty() {
let single = &text[text.len() - 1..];
if single == "'" || single == "\"" {
return single;
for quote in ["'''", "\"\"\"", "'", "\""] {
if text.ends_with(quote) {
return quote;
}
}