mirror of
https://github.com/typst/typst
synced 2025-08-26 04:34:14 +08:00
Add guard for potential empty labels from bibliography (#5776)
This commit is contained in:
parent
d90b5623d8
commit
43c3acdc4e
@ -54,7 +54,9 @@ pub struct Label(PicoStr);
|
|||||||
|
|
||||||
impl Label {
|
impl Label {
|
||||||
/// Creates a label from an interned string.
|
/// Creates a label from an interned string.
|
||||||
|
/// Callers need to ensure the given string is not empty.
|
||||||
pub fn new(name: PicoStr) -> Self {
|
pub fn new(name: PicoStr) -> Self {
|
||||||
|
debug_assert!(name != PicoStr::EMPTY);
|
||||||
Self(name)
|
Self(name)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -313,12 +313,17 @@ impl Bibliography {
|
|||||||
for (source, data) in sources.0.iter().zip(data) {
|
for (source, data) in sources.0.iter().zip(data) {
|
||||||
let library = decode_library(source, data)?;
|
let library = decode_library(source, data)?;
|
||||||
for entry in library {
|
for entry in library {
|
||||||
match map.entry(Label::new(PicoStr::intern(entry.key()))) {
|
let key = entry.key();
|
||||||
|
if key.is_empty() {
|
||||||
|
bail!("empty bibliography key found");
|
||||||
|
}
|
||||||
|
|
||||||
|
match map.entry(Label::new(PicoStr::intern(key))) {
|
||||||
indexmap::map::Entry::Vacant(vacant) => {
|
indexmap::map::Entry::Vacant(vacant) => {
|
||||||
vacant.insert(entry);
|
vacant.insert(entry);
|
||||||
}
|
}
|
||||||
indexmap::map::Entry::Occupied(_) => {
|
indexmap::map::Entry::Occupied(_) => {
|
||||||
duplicates.push(entry.key().into());
|
duplicates.push(key.into());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -38,6 +38,9 @@ struct Interner {
|
|||||||
pub struct PicoStr(NonZeroU64);
|
pub struct PicoStr(NonZeroU64);
|
||||||
|
|
||||||
impl PicoStr {
|
impl PicoStr {
|
||||||
|
/// Empty string as PicoStr
|
||||||
|
pub const EMPTY: PicoStr = PicoStr::constant("");
|
||||||
|
|
||||||
/// Intern a string at runtime.
|
/// Intern a string at runtime.
|
||||||
pub fn intern(string: &str) -> PicoStr {
|
pub fn intern(string: &str) -> PicoStr {
|
||||||
// Try to use bitcode or exception representations.
|
// Try to use bitcode or exception representations.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user