fix: renaming may cause a crash when encountering Unicode characters (#519)

This commit is contained in:
三咲雅 · Misaki Masa 2024-01-16 08:16:45 +08:00 committed by GitHub
parent cb80ca81da
commit 89848ad779
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -64,7 +64,12 @@ impl Manager {
let name = Self::empty_url_part(&hovered, opt.empty);
let cursor = match opt.cursor {
"start" => Some(0),
"before_ext" => name.rfind('.').filter(|&n| n != 0),
"before_ext" => name
.chars()
.rev()
.position(|c| c == '.')
.map(|i| name.chars().count() - i - 1)
.filter(|&i| i != 0),
_ => None,
};