From 1a0e13aecff06d147c0a9fb000717313e0b69763 Mon Sep 17 00:00:00 2001 From: Winston Chang Date: Mon, 26 Sep 2022 12:36:52 -0500 Subject: [PATCH 1/3] Bump version to 0.5.3.9000 --- DESCRIPTION | 2 +- NEWS.md | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/DESCRIPTION b/DESCRIPTION index 1337c94..cb9357a 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: webshot Title: Take Screenshots of Web Pages -Version: 0.5.3 +Version: 0.5.3.9000 Authors@R: c( person("Winston", "Chang", email = "winston@rstudio.com", role = c("aut", "cre")), person("Yihui", "Xie", role = "ctb"), diff --git a/NEWS.md b/NEWS.md index 6a6ab5f..1301ef7 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,7 @@ +webshot 0.5.3.9000 +============= + + webshot 0.5.3 ============= From d5110d3f70f9b5cf529d67539306c1c297598852 Mon Sep 17 00:00:00 2001 From: Winston Chang Date: Mon, 26 Sep 2022 12:38:31 -0500 Subject: [PATCH 2/3] Fix handling of windows paths with backslash --- DESCRIPTION | 4 +++- R/utils.R | 2 +- tests/testthat.R | 4 ++++ tests/testthat/test-url.R | 23 +++++++++++++++++++++++ 4 files changed, 31 insertions(+), 2 deletions(-) create mode 100644 tests/testthat.R create mode 100644 tests/testthat/test-url.R diff --git a/DESCRIPTION b/DESCRIPTION index cb9357a..babeedf 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -20,7 +20,8 @@ Suggests: httpuv, knitr, rmarkdown, - shiny + shiny, + testthat (>= 3.0.0) License: GPL-2 SystemRequirements: PhantomJS for taking screenshots, ImageMagick or GraphicsMagick and OptiPNG for manipulating images. @@ -28,3 +29,4 @@ RoxygenNote: 7.1.2 Encoding: UTF-8 URL: http://wch.github.io/webshot/, https://github.com/wch/webshot/ BugReports: https://github.com/wch/webshot/issues +Config/testthat/edition: 3 diff --git a/R/utils.R b/R/utils.R index c8584f9..e1e2746 100644 --- a/R/utils.R +++ b/R/utils.R @@ -353,7 +353,7 @@ fix_windows_url <- function(url) { # If it's a "c:/path/file.html" path, or contains any backslashs, like # "c:\path", "\\path\\file.html", or "/path\\file.html", we need to fix it # up. However, we need to leave paths that are already URLs alone. - if (grepl("^[a-zA-Z]:/", x) || + if (grepl("^[a-zA-Z]:[/\\]", x) || (!grepl(":", x, fixed = TRUE) && grepl("\\", x, fixed = TRUE))) { paste0("file:///", normalizePath(x, winslash = "/")) diff --git a/tests/testthat.R b/tests/testthat.R new file mode 100644 index 0000000..716d2f5 --- /dev/null +++ b/tests/testthat.R @@ -0,0 +1,4 @@ +library(testthat) +library(webshot) + +test_check("webshot") diff --git a/tests/testthat/test-url.R b/tests/testthat/test-url.R new file mode 100644 index 0000000..28417a7 --- /dev/null +++ b/tests/testthat/test-url.R @@ -0,0 +1,23 @@ +test_that("fix_windows_url works properly", { + testthat::skip_if_not(is_windows()) + + # Should add file:/// to file paths + expect_equal( + suppressWarnings(fix_windows_url("c:/path/file.html")), + "file:///c:/path/file.html" + ) + expect_equal( + suppressWarnings(fix_windows_url("c:\\path\\file.html")), + "file:///c:/path/file.html" + ) + + # Currently disabled because I'm not sure exactly should happen when there's + # not a leading drive letter like "c:" + # expect_equal(fix_windows_url("/path/file.html"), "file:///c:/path/file.html") + # expect_equal(fix_windows_url("\\path\\file.html"), "file:///c:/path/file.html") + # expect_equal(fix_windows_url("/path\\file.html"), "file:///c:/path/file.html") + + # Shouldn't affect proper URLs + expect_equal(fix_windows_url("file:///c:/path/file.html"), "file:///c:/path/file.html") + expect_equal(fix_windows_url("http://x.org/file.html"), "http://x.org/file.html") +}) From 6c9c3f12cb19070ea27c743c29b2c10419e14873 Mon Sep 17 00:00:00 2001 From: Winston Chang Date: Mon, 26 Sep 2022 12:47:30 -0500 Subject: [PATCH 3/3] Update NEWS --- NEWS.md | 1 + 1 file changed, 1 insertion(+) diff --git a/NEWS.md b/NEWS.md index 1301ef7..faf87fd 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,6 +1,7 @@ webshot 0.5.3.9000 ============= +* Fixed #112: handling of Windows paths of the form "c:\file\path.html" did not work correctly. ([#114](https://github.com/wch/webshot/pull/114)) webshot 0.5.3 =============