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

Ignore comments in block #718

Merged
merged 6 commits into from
Dec 29, 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 @@ -13,6 +13,8 @@ plumber 1.0.0.9999 Development version

### Bug fixes

* Ignore regular comments in block parsing (@meztez #718)

* Block parsing comments, tags and responses ordering match plumber api ordering. (#722)

* When calling `Plumber$handle()` and defining a new `PlumberEndpoint`, `...` will be checked for invalid names (@meztez, #677)
Expand Down
8 changes: 7 additions & 1 deletion R/plumb-block.R
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,16 @@ plumbBlock <- function(lineNum, file, envir = parent.frame()){
responses <- NULL
tags <- NULL
routerModifier <- NULL
while (lineNum > 0 && (stri_detect_regex(file[lineNum], pattern="^#['\\*]") || stri_trim_both(file[lineNum]) == "")){
while (lineNum > 0 && (stri_detect_regex(file[lineNum], pattern="^#['\\*]?|^\\s*$") || stri_trim_both(file[lineNum]) == "")){

line <- file[lineNum]

# If the line does not start with a plumber tag `#*` or `#'`, continue to next line
if (!stri_detect_regex(line, pattern="^#['\\*]")) {
lineNum <- lineNum - 1
next
}

epMat <- stri_match(line, regex="^#['\\*]\\s*@(get|put|post|use|delete|head|options|patch)(\\s+(.*)$)?")
if (!is.na(epMat[1,2])){
p <- stri_trim_both(epMat[1,4])
Expand Down
7 changes: 7 additions & 0 deletions tests/testthat/test-parse-block.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ test_that("trimws works", {

test_that("plumbBlock works", {
lines <- c(
"#* Plumber comment not reached",
"NULL",
"#* Plumber comments",
"",
" ",
"# Normal comments",
"#' @get /",
"#' @post /",
"#' @filter test",
Expand All @@ -18,6 +24,7 @@ test_that("plumbBlock works", {
expect_equal(b$paths[[1]], list(verb="GET", path="/"))
expect_equal(b$paths[[2]], list(verb="POST", path="/"))
expect_equal(b$filter, "test")
expect_equal(b$comments, " Plumber comments")

# due to covr changing some code, the return answer is very strange
# the tests below should be skipped on covr
Expand Down