Skip to content

Commit

Permalink
Escape md link targets for '%' (#1210)
Browse files Browse the repository at this point in the history
Closes #1209.
  • Loading branch information
gaborcsardi authored Mar 2, 2021
1 parent bcea96a commit 6c1e42f
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
3 changes: 3 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# roxygen2 (development version)

* Percent signs in markdown link targets, e.g. `[text](https://foo/ba%20r)`
are now handled correctly (#1209).

* The new `@exmaplesIf` tag can be used to create conditional
examples. These examples only run if a specified condition
holds (#962).
Expand Down
5 changes: 4 additions & 1 deletion R/markdown.R
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,10 @@ mdxml_link <- function(xml, state) {
} else if (dest == "" || dest == xml_text(xml)) {
paste0("\\url{", escape_comment(xml_text(xml)), "}")
} else {
paste0("\\href{", dest, "}{", mdxml_link_text(contents, state), "}")
paste0(
"\\href{", escape_comment(dest), "}",
"{", mdxml_link_text(contents, state), "}"
)
}
}

Expand Down
16 changes: 16 additions & 0 deletions tests/testthat/test-markdown-link.R
Original file line number Diff line number Diff line change
Expand Up @@ -446,3 +446,19 @@ test_that("linking to self is unqualified", {
"foo \\code{\\link[=fun]{fun()}} and \\link{obj} bar"
)
})

test_that("percents are escaped in link targets", {
out1 <- roc_proc_text(rd_roclet(), "
#' Title
#'
#' [link % text](https://foo.bar/link%20target)
#' @md
foo <- function() {}")[[1]]
out2 <- roc_proc_text(rd_roclet(), "
#' Title
#'
#' \\href{https://foo.bar/link%20target}{link % text}
#' @md
foo <- function() {}")[[1]]
expect_equivalent_rd(out1, out2)
})

0 comments on commit 6c1e42f

Please sign in to comment.