Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

prepend a '/' at the beginning of all paths #656

Merged
merged 2 commits into from
Aug 21, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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")
})