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

Fix handling of Windows paths with backslash #114

Merged
merged 3 commits into from
Sep 26, 2022
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
6 changes: 4 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -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 = "[email protected]", role = c("aut", "cre")),
person("Yihui", "Xie", role = "ctb"),
Expand All @@ -20,11 +20,13 @@ 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.
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
5 changes: 5 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
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
=============

Expand Down
2 changes: 1 addition & 1 deletion R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "/"))
Expand Down
4 changes: 4 additions & 0 deletions tests/testthat.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
library(testthat)
library(webshot)

test_check("webshot")
23 changes: 23 additions & 0 deletions tests/testthat/test-url.R
Original file line number Diff line number Diff line change
@@ -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")
})