Skip to content

Commit

Permalink
Allow colons in uri templates (#393)
Browse files Browse the repository at this point in the history
Fixes #389
  • Loading branch information
hadley authored Nov 14, 2023
1 parent 5fba4f9 commit ad76565
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
3 changes: 3 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
6 changes: 3 additions & 3 deletions R/req-template.R
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
Expand Down
6 changes: 6 additions & 0 deletions tests/testthat/test-req-template.R
Original file line number Diff line number Diff line change
Expand Up @@ -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:/")
})

0 comments on commit ad76565

Please sign in to comment.