From dacab7869fafb4963b2d9739fd982aa531ce2578 Mon Sep 17 00:00:00 2001 From: Neill Johnston Date: Wed, 30 Aug 2023 11:17:27 -0400 Subject: [PATCH] Fix: ends-with (#2034) --- crates/typst/src/eval/str.rs | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/crates/typst/src/eval/str.rs b/crates/typst/src/eval/str.rs index b21d2ff9d..140f71465 100644 --- a/crates/typst/src/eval/str.rs +++ b/crates/typst/src/eval/str.rs @@ -116,7 +116,22 @@ impl Str { match pattern { StrPattern::Str(pat) => self.0.ends_with(pat.as_str()), StrPattern::Regex(re) => { - re.find_iter(self).last().map_or(false, |m| m.end() == self.0.len()) + let mut start_byte = 0; + while let Some(mat) = re.find_at(self, start_byte) { + if mat.end() == self.0.len() { + return true; + } + + // There might still be a match overlapping this one, so + // restart at the next code point + if let Some(c) = &self[mat.start()..].chars().next() { + start_byte = mat.start() + c.len_utf8(); + } else { + break; + } + } + + false } } }