Skip to content

Commit

Permalink
Escape "%" etc. in URLs (#1416)
Browse files Browse the repository at this point in the history
Fixes #1415
  • Loading branch information
HenningLorenzen-ext-bayer committed Nov 16, 2023
1 parent a5d9561 commit 335448d
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
3 changes: 3 additions & 0 deletions NEWS.md
@@ -1,5 +1,8 @@
# roxygen2 (development version)

* `URL` and `BugReports` fields in `DESCRIPTION` may now contain
percent-encoded URLs (@HenningLorenzen-ext-bayer, #1415).

* `@inherit` can now also inherit from `@format` (#1293).

* `@describeIn()` gives a more informative warning if you use it with an
Expand Down
5 changes: 3 additions & 2 deletions R/object-package.R
@@ -1,15 +1,16 @@
package_seealso <- function(URL, BugReports) {
itemize("Useful links:", package_seealso_urls(URL, BugReports))
}

package_seealso_urls <- function(URL = NULL, BugReports = NULL) {
if (!is.null(URL)) {
links <- paste0("\\url{", strsplit(URL, ",\\s+")[[1]], "}")
links <- paste0("\\url{", escape(strsplit(URL, ",\\s+")[[1]]), "}")
links <- gsub("\\url\\{https://doi.org/", "\\doi{", links)
} else {
links <- character()
}
if (!is.null(BugReports)) {
links <- c(links, paste0("Report bugs at \\url{", BugReports, "}"))
links <- c(links, paste0("Report bugs at \\url{", escape(BugReports), "}"))
}

links
Expand Down
14 changes: 14 additions & 0 deletions tests/testthat/test-object-package.R
Expand Up @@ -25,6 +25,20 @@ test_that("useful message if Authors@R is corrupted", {
})
})

test_that("can convert quote percentage signs in urls", {
expect_equal(
package_seealso_urls("https://www.foo.bar/search?q=see%20also"),
"\\url{https://www.foo.bar/search?q=see\\%20also}"
)

expect_equal(
package_seealso_urls(
BugReports = "https://www.foo.bar/search?q=bug%20report"
),
"Report bugs at \\url{https://www.foo.bar/search?q=bug\\%20report}"
)
})

test_that("can convert DOIs in url", {
expect_equal(
package_seealso_urls("https://doi.org/10.5281/zenodo.1485309"),
Expand Down

0 comments on commit 335448d

Please sign in to comment.