diff --git a/NEWS.md b/NEWS.md index 3952e86ac..af7da1d25 100644 --- a/NEWS.md +++ b/NEWS.md @@ -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). diff --git a/R/plumber-step.R b/R/plumber-step.R index 015e67fac..71599c646 100644 --- a/R/plumber-step.R +++ b/R/plumber-step.R @@ -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 diff --git a/tests/testthat/test-plumber.R b/tests/testthat/test-plumber.R index d358abde3..4e3852194 100644 --- a/tests/testthat/test-plumber.R +++ b/tests/testthat/test-plumber.R @@ -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") +})