diff --git a/NEWS.md b/NEWS.md index ceecdfe9..4da4a06d 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,8 @@ # httr2 (development version) +* `req_template()` now works when you have a bare `:` in a template that + uses "uri" style (#389). + # httr2 1.0.0 ## Function lifecycle diff --git a/R/req-template.R b/R/req-template.R index 98aa8716..278b292a 100644 --- a/R/req-template.R +++ b/R/req-template.R @@ -112,10 +112,10 @@ template_vars <- function(x, type) { } template_type <- function(x) { - if (grepl(":", x)) { - "colon" - } else if (grepl("\\{\\w+?\\}", x)) { + if (grepl("\\{\\w+?\\}", x)) { "uri" + } else if (grepl(":", x)) { + "colon" } else { "none" } diff --git a/tests/testthat/test-req-template.R b/tests/testthat/test-req-template.R index b19d0887..219cc3ae 100644 --- a/tests/testthat/test-req-template.R +++ b/tests/testthat/test-req-template.R @@ -54,3 +54,9 @@ test_that("supports three template styles", { expect_equal(template_process("/{x}/"), "/x/") expect_equal(template_process("/constant"), "/constant") }) + +test_that("can use colon in uri style", { + x <- "x" + expect_equal(template_process("/:{x}:/"), "/:x:/") +}) +