Panics · P02 Typography: Link takes its handler, an unknown zone reads as UTC and says so, a long highlight query logs
This commit is contained in:
1 parent
e5166e9e26
commit
f46cc4e7c3
11 files changed
+132
-60
No files matched your search
@@ -187,13 +187,19 @@ impl Highlight {
|
||||
let ranges = if query.is_empty() {
|
||||
Vec::new()
|
||||
} else {
|
||||
RegexBuilder::new(®ex::escape(query))
|
||||
match RegexBuilder::new(®ex::escape(query))
|
||||
.case_insensitive(true)
|
||||
.build()
|
||||
.expect("an escaped literal is a valid regex")
|
||||
.find_iter(&text)
|
||||
.map(|found| found.range())
|
||||
.collect()
|
||||
{
|
||||
Ok(found) => found.find_iter(&text).map(|found| found.range()).collect(),
|
||||
Err(error) => {
|
||||
log::error!(
|
||||
"highlight: no marks for a {}-byte query: {error}",
|
||||
query.len()
|
||||
);
|
||||
Vec::new()
|
||||
}
|
||||
}
|
||||
};
|
||||
Self { text, ranges }
|
||||
}
|
||||
@@ -216,6 +222,12 @@ impl RenderOnce for Highlight {
|
||||
mod tests {
|
||||
use super::{Highlight, Range};
|
||||
|
||||
#[test]
|
||||
fn a_query_past_the_regex_limit_marks_nothing() {
|
||||
let long = "a".repeat(500_000);
|
||||
assert!(Highlight::matching("aaa", &long).ranges.is_empty());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn matching_finds_every_case_insensitive_hit() {
|
||||
let found = Highlight::matching("Ely, ely, ELY and élan", "ely");
|
||||
|
||||
Reference in new issue
Block a user