Make `World::font` implementations safe (#6117)
This commit is contained in:
parent
efdb75558f
commit
758ee78ef5
|
|
@ -210,7 +210,9 @@ impl World for SystemWorld {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn font(&self, index: usize) -> Option<Font> {
|
fn font(&self, index: usize) -> Option<Font> {
|
||||||
self.fonts[index].get()
|
// comemo's validation may invoke this function with an invalid index. This is
|
||||||
|
// impossible in typst-cli but possible if a custom tool mutates the fonts.
|
||||||
|
self.fonts.get(index)?.get()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn today(&self, offset: Option<i64>) -> Option<Datetime> {
|
fn today(&self, offset: Option<i64>) -> Option<Datetime> {
|
||||||
|
|
|
||||||
|
|
@ -97,7 +97,7 @@ impl World for TestWorld {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn font(&self, index: usize) -> Option<Font> {
|
fn font(&self, index: usize) -> Option<Font> {
|
||||||
Some(self.base.fonts[index].clone())
|
self.base.fonts.get(index).cloned()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn today(&self, _: Option<i64>) -> Option<Datetime> {
|
fn today(&self, _: Option<i64>) -> Option<Datetime> {
|
||||||
|
|
|
||||||
|
|
@ -498,7 +498,7 @@ impl World for DocWorld {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn font(&self, index: usize) -> Option<Font> {
|
fn font(&self, index: usize) -> Option<Font> {
|
||||||
Some(FONTS.1[index].clone())
|
FONTS.1.get(index).cloned()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn today(&self, _: Option<i64>) -> Option<Datetime> {
|
fn today(&self, _: Option<i64>) -> Option<Datetime> {
|
||||||
|
|
|
||||||
|
|
@ -67,7 +67,7 @@ impl World for TestWorld {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn font(&self, index: usize) -> Option<Font> {
|
fn font(&self, index: usize) -> Option<Font> {
|
||||||
Some(self.base.fonts[index].clone())
|
self.base.fonts.get(index).cloned()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn today(&self, _: Option<i64>) -> Option<Datetime> {
|
fn today(&self, _: Option<i64>) -> Option<Datetime> {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue