diff --git a/NEWS.md b/NEWS.md index 6c1aedb7e..200aa1530 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,6 @@ # pkgdown (development version) +* `build_home()` now correctly escapes special HTML characters in the bibtex citation (#2022). * `build_articles()` now reports if you are missing alt-text for any images (#2357). * `check_pkgdown()` and `pkgdown_sitrep()` have been unified so that they both report on the same problems. They now only differ in the style of their output: `pkgdown_sitrep()` reports whether each category is ok or not ok, while `check_pkgdown()` errors on the first issue (#2463). * `build_site()` automatically runs `pkgdown_sitrep()` at the start of the process (#2380). diff --git a/inst/BS3/templates/content-citation-authors.html b/inst/BS3/templates/content-citation-authors.html index 5a40700e1..2ba7cf2c8 100644 --- a/inst/BS3/templates/content-citation-authors.html +++ b/inst/BS3/templates/content-citation-authors.html @@ -26,7 +26,7 @@
{{{bibtex}}}+
{{bibtex}}{{/citations}} diff --git a/inst/BS5/templates/content-citation-authors.html b/inst/BS5/templates/content-citation-authors.html index 805d86924..06a92899e 100644 --- a/inst/BS5/templates/content-citation-authors.html +++ b/inst/BS5/templates/content-citation-authors.html @@ -25,7 +25,7 @@
{{{bibtex}}}+
{{bibtex}}{{/citations}} diff --git a/tests/testthat/test-build-home-authors.R b/tests/testthat/test-build-home-authors.R index 99a75c814..0469b4f56 100644 --- a/tests/testthat/test-build-home-authors.R +++ b/tests/testthat/test-build-home-authors.R @@ -109,3 +109,27 @@ test_that("multiple citations all have HTML and BibTeX formats", { citations <- data_citations(path) expect_snapshot_output(citations) }) + +test_that("bibtex is escaped", { + pkg <- local_pkgdown_site(meta = " + template: + bslib: + version: 5 + ") + dir_create(path(pkg$src_path, "inst")) + write_lines(path = path(pkg$src_path, "inst", "CITATION"), c( + 'citEntry(', + ' entry = "Article",', + ' title="test special HTML characters: <&>",', + ' author="x",', + ' journal="x",', + ' year="2017"', + ')' + )) + + suppressMessages(init_site(pkg)) + suppressMessages(build_citation_authors(pkg)) + html <- xml2::read_html(path(pkg$dst_path, "authors.html")) + + expect_match(xpath_text(html, "//pre"), "<&>", fixed = TRUE) +})