From 15ea432b3524df2df0e13c3fe73ef7260c6be027 Mon Sep 17 00:00:00 2001 From: Hadley Wickham Date: Wed, 22 Jun 2022 17:30:06 -0500 Subject: [PATCH] Revert #2104 Because it causes spurious matches when if links are already present. Fixes #2122. --- NEWS.md | 3 +++ R/repo.R | 4 ++-- tests/testthat/test-repo.R | 9 ++++----- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/NEWS.md b/NEWS.md index 9984ee206..e8350f505 100644 --- a/NEWS.md +++ b/NEWS.md @@ -6,6 +6,9 @@ * Correctly generates link targets for topics that have a file name ending in `.` (#2128). +* Reverted #2030 so links to `@username` in NEWS.md work in fewer places. + See #2122 for details. + * Restore accidentally nerfed `has_keyword()` and `has_concept()` reference selectors (#2126). diff --git a/R/repo.R b/R/repo.R index 30638616b..9229780b5 100644 --- a/R/repo.R +++ b/R/repo.R @@ -38,12 +38,12 @@ repo_auto_link <- function(pkg, text) { if (!is.null(url$user)) { user_link <- paste0("\\1@\\2") - text <- gsub("(\\s|[(>])@([-\\w]+)", user_link, text, perl = TRUE) + text <- gsub("(\\s|^|\\()@([-\\w]+)", user_link, text, perl = TRUE) } if (!is.null(url$issue)) { issue_link <- paste0("#\\2") - text <- gsub("(\\s|[(>])#(\\d+)", paste0("\\1", issue_link), text, perl = TRUE) + text <- gsub("(\\(|\\s)#(\\d+)", paste0("\\1", issue_link), text, perl = TRUE) if (!is.null(pkg$repo$jira_projects)) { issue_link <- paste0("\\1\\2") diff --git a/tests/testthat/test-repo.R b/tests/testthat/test-repo.R index b4894cd4f..14122ee34 100644 --- a/tests/testthat/test-repo.R +++ b/tests/testthat/test-repo.R @@ -6,17 +6,16 @@ test_that("authors are automatically linked", { # email addresses shouldn't get linked expect_equal(repo_auto_link(pkg, "x@y.com"), "x@y.com") - # must have leading whitespace or open parens or end of HTML tag + # must have leading whitespace or open parens + expect_equal(repo_auto_link(pkg, "@y"), "@y") expect_equal(repo_auto_link(pkg, " @y"), " @y") expect_equal(repo_auto_link(pkg, "(@y)"), "(@y)") - expect_equal(repo_auto_link(pkg, "

@y"), "

@y") }) test_that("issues are automatically linked", { pkg <- list(repo = repo_meta(issue = "TEST/")) - expect_equal(repo_auto_link(pkg, " #123"), " #123") - expect_equal(repo_auto_link(pkg, "(#123)"), "(#123)") - expect_equal(repo_auto_link(pkg, "

#123"), "

#123") + expect_equal(repo_auto_link(pkg, "(#123"), "(#123") + expect_equal(repo_auto_link(pkg, "in #123"), "in #123") }) test_that("URLs with hash (#) are preserved", {