mirror of
https://github.com/typst/typst
synced 2025-08-24 03:34:14 +08:00
fix: silent hayagriva bibliography parsing error due very lenient biblatex parser
Fixes #6030
This commit is contained in:
parent
a5f410a76d
commit
9e820f883e
@ -412,8 +412,12 @@ fn decode_library(
|
||||
|
||||
// If it can be decoded as BibLaTeX, we use that isntead.
|
||||
let bib_errs = match hayagriva::io::from_biblatex_str(data) {
|
||||
Ok(library) => return Ok(library),
|
||||
Err(err) => err,
|
||||
// If the file is almost valid yaml, but contains no `@` character
|
||||
// it will be successfully parsed as an empty BibLaTeX library,
|
||||
// since BibLaTeX does support arbitrary text outside of entries.
|
||||
Ok(library) if !library.is_empty() => return Ok(library),
|
||||
Ok(_) => None,
|
||||
Err(err) => Some(err),
|
||||
};
|
||||
|
||||
// If neither decoded correctly, check whether `:` or `{` appears
|
||||
@ -429,15 +433,18 @@ fn decode_library(
|
||||
}
|
||||
}
|
||||
|
||||
if yaml > biblatex {
|
||||
if let Some(loc) = haya_err.location() {
|
||||
let line = loc.line();
|
||||
bail!(source_span, "failed to parse YAML ({line}: {haya_err})")
|
||||
} else {
|
||||
bail!(source_span, "failed to parse YAML ({haya_err})")
|
||||
match bib_errs {
|
||||
Some(bib_errs) if biblatex >= yaml => {
|
||||
bail!(format_biblatex_error(source_span, source, data, bib_errs))
|
||||
}
|
||||
_ => {
|
||||
if let Some(loc) = haya_err.location() {
|
||||
let line = loc.line();
|
||||
bail!(source_span, "failed to parse YAML ({line}: {haya_err})")
|
||||
} else {
|
||||
bail!(source_span, "failed to parse YAML ({haya_err})")
|
||||
}
|
||||
}
|
||||
} else {
|
||||
bail!(format_biblatex_error(source_span, source, data, bib_errs))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user