Fix off by one error in highlight (#649)

This commit is contained in:
ves 2024-08-11 01:01:22 +03:00 committed by GitHub
parent f8cfa57f89
commit 62f53e47bb
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 30 additions and 6 deletions

25
Cargo.lock generated
View File

@ -19,13 +19,14 @@ checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe"
[[package]]
name = "ahash"
version = "0.8.3"
version = "0.8.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2c99f64d1e06488f620f932677e24bc6e2897582980441ae90a671415bd7ec2f"
checksum = "e89da841a80418a9b391ebaea17f5c112ffaaa96f621d2c285b5174da76b9011"
dependencies = [
"cfg-if",
"once_cell",
"version_check",
"zerocopy",
]
[[package]]
@ -3041,6 +3042,26 @@ dependencies = [
"windows-sys 0.48.0",
]
[[package]]
name = "zerocopy"
version = "0.7.35"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1b9b4fd18abc82b8136838da5d50bae7bdea537c574d8dc1a34ed098d6c166f0"
dependencies = [
"zerocopy-derive",
]
[[package]]
name = "zerocopy-derive"
version = "0.7.35"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fa4f8080344d4671fb4e831a13ad1e68092748387dfc4f55e356242fae12ce3e"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "zeroize"
version = "1.8.1"

View File

@ -395,9 +395,10 @@ impl MessageData {
) -> Vec<Span<'s>> {
static EMOTE_FINDER: Lazy<memmem::Finder> =
Lazy::new(|| memmem::Finder::new(ZERO_WIDTH_SPACE_STR));
let line_is_empty = line.is_empty();
// A line contains emotes if `emotes` is not empty and `line` starts with a unicode placeholder or contains ZWS.
if emotes.is_empty()
let spans = if emotes.is_empty()
|| (!line.starts_with(PRIVATE_USE_UNICODE)
&& EMOTE_FINDER.find(line.as_bytes()).is_none())
{
@ -436,7 +437,9 @@ impl MessageData {
*start_index = start_index.saturating_sub(ZERO_WIDTH_SPACE_STR.len());
spans
}
};
*start_index += usize::from(!line_is_empty);
spans
}
pub fn to_vec(
@ -846,7 +849,7 @@ mod tests {
assert_eq!(emotes, EMOTES_ID_PID);
assert_eq!(start_index, line.len());
assert_eq!(start_index - 1, line.len());
assert_eq!(
spans,
@ -899,7 +902,7 @@ mod tests {
);
assert!(emotes.is_empty());
assert_eq!(start_index, line.len());
assert_eq!(start_index - 1, line.len());
assert_eq!(
spans,