Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 54 additions & 0 deletions src/csl/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3798,6 +3798,60 @@ mod tests {
assert_eq!(c1, "Downs (1957)");
assert_eq!(c2, "Brady & Collier (2010)");
}

#[test]
#[cfg(feature = "archive")]
/// A webpage with only a year (no month/day) as its issued date must not render a dangling delimiter before the (empty) month/day part.
///
/// See https://github.com/typst/hayagriva/issues/246
fn issue_year_only_date_apa() {
let yaml = r#"
nistCVE:
type: Web
author: "NIST"
title: "CVE-2021-44228"
date: "2021"
url:
value: "https://nvd.nist.gov/vuln/detail/CVE-2021-44228"
date: 2024-10-28
"#;

let library = from_yaml_str(yaml).unwrap();
let apa = archive::ArchivedStyle::AmericanPsychologicalAssociation.get();
let citationberg::Style::Independent(apa) = apa else { unreachable!() };
let locales = archive::locales();

let mut driver = BibliographyDriver::new();
driver.citation(CitationRequest::new(
vec![CitationItem::with_entry(library.iter().next().unwrap())],
&apa,
None,
&locales,
None,
));

let finished = driver.finish(BibliographyRequest {
style: &apa,
locale: None,
locale_files: &locales,
});

let mut bib_entry = String::new();
finished
.bibliography
.unwrap()
.items
.remove(0)
.content
.write_buf(&mut bib_entry, BufWriteFormat::Plain)
.unwrap();

assert_eq!(
bib_entry,
"NIST. (2021). CVE-2021-44228. https://nvd.nist.gov/vuln/detail/CVE-2021-44228"
);
}

#[test]
#[cfg(feature = "archive")]
/// See https://github.com/typst/hayagriva/issues/48
Expand Down
15 changes: 14 additions & 1 deletion src/csl/rendering/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -792,7 +792,20 @@ impl RenderCsl for citationberg::Date {
if !self.will_render(ctx, variable.into()) {
(false, UsageInfo::default())
} else {
let has_non_empty_vars = ctx.resolve_date_variable(variable).is_some();
let base = self.form.and_then(|form| ctx.localized_date(form));
let parts = self.parts.or(base.and_then(|b| b.parts)).unwrap_or_default();

let has_non_empty_vars =
ctx.resolve_date_variable(variable).is_some_and(|date| {
base.unwrap_or(self).date_part.iter().any(|part| match part.name {
DatePartName::Year => true,
DatePartName::Month => {
(parts.has_month() || date.season.is_some())
&& (date.month.is_some() || date.season.is_some())
}
DatePartName::Day => parts.has_day() && date.day.is_some(),
})
});
(
has_non_empty_vars,
UsageInfo {
Expand Down
1 change: 1 addition & 0 deletions tests/citeproc-pass.txt
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ fullstyles_ChicagoNoteWithBibliographyWithPublisher
group_ComplexNesting
group_ShortOutputOnly
group_SuppressTermInMacro
group_SuppressTermWhenNoOutputFromPartialDate
group_SuppressValueWithEmptySubgroup
group_SuppressWithEmptyNestedDateNode
integration_CitationSort
Expand Down
Loading