From d499d2a8fc38ea39247dca7ec1f6e0cc570141c0 Mon Sep 17 00:00:00 2001 From: Yihui Xie Date: Sun, 26 May 2024 14:22:10 -0500 Subject: [PATCH] fix #2343: remove anything after comma or white spaces (including \n) in package URL --- DESCRIPTION | 2 +- NEWS.md | 4 ++++ R/citation.R | 9 ++------- 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index db64333c5c..83d07a9d5d 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Package: knitr Type: Package Title: A General-Purpose Package for Dynamic Report Generation in R -Version: 1.46.4 +Version: 1.46.5 Authors@R: c( person("Yihui", "Xie", role = c("aut", "cre"), email = "xie@yihui.name", comment = c(ORCID = "0000-0003-0645-5666")), person("Abhraneel", "Sarma", role = "ctb"), diff --git a/NEWS.md b/NEWS.md index cf7ad7b198..735d4cd268 100644 --- a/NEWS.md +++ b/NEWS.md @@ -6,6 +6,10 @@ - `write_bib()` now escapes all non-escaped "&" in the bibliography by default. Previously, it only escaped the title field of the package citation. You can disable the escape with the argument `tweak = FALSE` (thanks, @HedvigS #2335, @atusy #2342). +## BUG FIXES + +- Fixed a bug that `write_bib()` fails to use the first URL of a package when multiple URLs are provided in DESCRIPTION and separated by `\n` (thanks, @bastistician, #2343). + ## MINOR CHANGES - The syntax highlighting LaTeX commands for Rnw documents, `\hlstr` and `\hlstd`, were renamed to `\hlsng` and `\hldef`, respectively, to maintain consistency with Andrew Simon's highlight package (thanks, @dcser123, #2341). diff --git a/R/citation.R b/R/citation.R index ff08fea56f..2128349b5f 100644 --- a/R/citation.R +++ b/R/citation.R @@ -90,13 +90,8 @@ write_bib = function( # don't use the citation() URL if the package has provided its own URL cite = citation(pkg, auto = if (is.null(meta$URL)) meta else { if (packageURL) meta$Repository = meta$RemoteType = NULL - # the package may have provided multiple URLs, in which case we use the - # first. We also work around a bug in citation() up to R 4.3.1. The grep - # pattern here is problematic, but it's what citation() was using. - if (getRversion() < '4.3.2' && grepl('[, ]', meta$URL)) - meta$URL = sub('[, ].*', '', meta$URL) - # always remove URLs after the first one - meta$URL = sub(',? .*', '', meta$URL) + # use the first URL in case the package provided multiple URLs + meta$URL = sub('[, \t\n].*', '', meta$URL) meta }) if (tweak) {