Skip to content

Commit 95eed06

Browse files
authored
file.path.ci is too loose with file matching (#2012)
because the `pattern` argument in `list.files` is a regexp and not literal string. This fixes rstudio/flexdashboard#298
1 parent 9c14988 commit 95eed06

File tree

4 files changed

+25
-3
lines changed

4 files changed

+25
-3
lines changed

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ Imports:
9696
Suggests:
9797
shiny (>= 0.11),
9898
tufte,
99-
testthat (>= 2.0.0),
99+
testthat (>= 3.0.0),
100100
digest,
101101
dygraphs,
102102
vctrs,

NEWS.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ rmarkdown 2.7
77

88
- Fix an issue with line numbering in code chunks when `.numberlines` with Pandoc's highlighting (thanks, @aosavi, #1876)
99

10+
- Fix an issue with shiny runtime and `global.R` (thanks, @liaojiahui-r, rstudio/flexdashboard#298)
11+
1012
- Accept `latex="{options}"`, `latex=1`, or `latex=true` for Latex Divs.
1113

1214
- Add `output_format_filter` function to `default_site_generator()`. Enables custom site generators to customize or even entirely replace the output format right before rendering of each page.

R/shiny.R

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -485,8 +485,10 @@ file.path.ci <- function(dir, name) {
485485

486486
matches <- list.files(dir, name, ignore.case = TRUE, full.names = TRUE,
487487
include.dirs = TRUE)
488-
if (length(matches) == 0)
489-
return(default)
488+
# name is used as a pattern above and can match other files
489+
# so we need to filter as if it was literal string
490+
matches <- matches[tolower(name) == tolower(basename(matches))]
491+
if (length(matches) == 0) return(default)
490492
return(matches[[1]])
491493
}
492494

tests/testthat/test-shiny.R

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
test_that("file.path.ci returns correctly no matter the case", {
2+
# TODO: added for new tests - to remove when switching the package to edition 3
3+
local_edition(3)
4+
tmp_dir <- withr::local_tempdir()
5+
expect_equal(file.path.ci(tmp_dir, "global.R"), file.path(tmp_dir, "global.R"))
6+
7+
withr::local_dir(tmp_dir)
8+
expect_equal_file <- function(file, tmp_dir, default = file) {
9+
withr::local_file(file); xfun::write_utf8("#dummy", file)
10+
expect_equal(file.path.ci(!!tmp_dir, "global.R"), file.path(!!tmp_dir, !!default))
11+
}
12+
expect_equal_file("global.R", tmp_dir)
13+
# on windows case in filename does not matter
14+
# & MacOs in GHA is case insensitive
15+
if (xfun::is_linux()) expect_equal_file("global.r", tmp_dir)
16+
expect_equal_file("global.R", "donotexist")
17+
expect_equal_file("global.Rmd", tmp_dir, "global.R")
18+
})

0 commit comments

Comments
 (0)