summaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
authorNeill Johnston <neilljohnston30@gmail.com>2023-08-30 11:17:27 -0400
committerGitHub <noreply@github.com>2023-08-30 17:17:27 +0200
commitdacab7869fafb4963b2d9739fd982aa531ce2578 (patch)
tree9b35f9bc5094f998fb397e0bff8eceea9d9ca190 /crates
parent5b36b462301d2074791d72ea6b1291d8120defb1 (diff)
Fix: ends-with (#2034)
Diffstat (limited to 'crates')
-rw-r--r--crates/typst/src/eval/str.rs17
1 files changed, 16 insertions, 1 deletions
diff --git a/crates/typst/src/eval/str.rs b/crates/typst/src/eval/str.rs
index b21d2ff9..140f7146 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
}
}
}