Skip to content

Commit

Permalink
prepend a '/' at the beginning of all paths (#656)
Browse files Browse the repository at this point in the history
  • Loading branch information
schloerke authored Aug 21, 2020
1 parent 9a7b6eb commit af4adc3
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 0 deletions.
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,8 @@ both UIs integration are available from https://github.com/meztez/rapidoc/ and h

### Bug fixes

* Paths that are missing a leading `/` have a `/` prepended to the path location. (#656)

* Handle plus signs in URI as space characters instead of actual plus signs (@meztez, #618)

* Modified images serialization to use content-type serializer. Fixes issue with images pre/postserialize hooks (@meztez, #518).
Expand Down
5 changes: 5 additions & 0 deletions R/plumber-step.R
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,11 @@ PlumberEndpoint <- R6Class(
#' They can also be provided manually for historical reasons.
#' @return A new `PlumberEndpoint` object
initialize = function(verbs, path, expr, envir, serializer, parsers, lines, params, comments, responses, tags) {

if (substr(path, 1,1) != "/") {
path <- paste0("/", path)
}

self$verbs <- verbs
self$path <- path

Expand Down
9 changes: 9 additions & 0 deletions tests/testthat/test-plumber.R
Original file line number Diff line number Diff line change
Expand Up @@ -509,3 +509,12 @@ test_that("removeHandle works", {
expect_equal(length(pr$endpoints[[1]]), 1L)
expect_equal(pr$endpoints[[1]][[1]]$path, "/path2")
})


test_that("routes that don't start with a slash are prepended with a slash", {
pr <- pr()
pr$handle("GET", "nested/path/here", function(){})

expect_equal(length(pr$endpoints[[1]]), 1L)
expect_equal(pr$endpoints[[1]][[1]]$path, "/nested/path/here")
})

0 comments on commit af4adc3

Please sign in to comment.