mirror of
https://github.com/typst/typst
synced 2025-08-25 04:04:12 +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.
|
// If it can be decoded as BibLaTeX, we use that isntead.
|
||||||
let bib_errs = match hayagriva::io::from_biblatex_str(data) {
|
let bib_errs = match hayagriva::io::from_biblatex_str(data) {
|
||||||
Ok(library) => return Ok(library),
|
// If the file is almost valid yaml, but contains no `@` character
|
||||||
Err(err) => err,
|
// 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
|
// If neither decoded correctly, check whether `:` or `{` appears
|
||||||
@ -429,15 +433,18 @@ fn decode_library(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if yaml > biblatex {
|
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() {
|
if let Some(loc) = haya_err.location() {
|
||||||
let line = loc.line();
|
let line = loc.line();
|
||||||
bail!(source_span, "failed to parse YAML ({line}: {haya_err})")
|
bail!(source_span, "failed to parse YAML ({line}: {haya_err})")
|
||||||
} else {
|
} else {
|
||||||
bail!(source_span, "failed to parse YAML ({haya_err})")
|
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