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

Allow to pass resource path that starts with . #2981

Merged
merged 4 commits into from Jul 27, 2020
Merged

Allow to pass resource path that starts with . #2981

merged 4 commits into from Jul 27, 2020

Conversation

ColinFay
Copy link
Contributor

This will close #2980

@CLAassistant
Copy link

CLAassistant commented Jul 24, 2020

CLA assistant check
All committers have signed the CLA.

@ColinFay
Copy link
Contributor Author

Not sure why this is failing here: https://github.com/rstudio/shiny/pull/2981/checks?check_run_id=905762561

Copy link
Collaborator

@wch wch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I support this change, but have a couple comments. The test failure is unrelated: it's happening because the R-devel builds for Mac OS X have disappeared from https://mac.r-project.org/

R/server.R Outdated
@@ -71,7 +71,7 @@ registerClient <- function(client) {
#' @export
addResourcePath <- function(prefix, directoryPath) {
if (length(prefix) != 1) stop("prefix must be of length 1")
if (!grepl('^[a-z0-9\\-_][a-z0-9\\-_.]*$', prefix, ignore.case = TRUE, perl = TRUE)) {
if (!grepl('^[a-z0-9\\-_\\.][a-z0-9\\-_.]*$', prefix, ignore.case = TRUE, perl = TRUE)) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this can be simplified to just:

'^[a-z0-9\\-_.]+$'

However, we should also disallow prefixes that consist only of . characters - that could lead to unnecessary confusion.

@ColinFay
Copy link
Contributor Author

Ah, I hadn't think about the use of dot only.

I've pushed a new test to check if the prefix is made only of dots (that would also cacth "..").

fn <- function(prefix) {
  if (grepl("^\\.+$", prefix)) stop("prefix can't be composed of dots only") else "ok"
}

fn(".")
#> Error in fn("."): prefix can't be composed of dots only
fn("..")
#> Error in fn(".."): prefix can't be composed of dots only
fn(".well-known")
#> [1] "ok"

Created on 2020-07-25 by the reprex package (v0.3.0)

R/server.R Outdated
@@ -72,7 +72,7 @@ registerClient <- function(client) {
addResourcePath <- function(prefix, directoryPath) {
if (length(prefix) != 1) stop("prefix must be of length 1")
if (grepl("^\\.+$", prefix)) stop("prefix can't be composed of dots only")
if (!grepl('^[a-z0-9\\-_\\.][a-z0-9\\-_.]*$', prefix, ignore.case = TRUE, perl = TRUE)) {
if (!grepl('[a-z0-9\\-_.]*$', prefix, ignore.case = TRUE, perl = TRUE)) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs a + instead of * -- otherwise it'll allow empty strings.

@ColinFay
Copy link
Contributor Author

Argh, sure.

Done in the last commit ✅

@wch wch self-requested a review July 27, 2020 19:26
@wch wch merged commit 1354d3d into rstudio:master Jul 27, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

addResourcePath should allow resources that starts with a dot
3 participants