Skip to content

Commit

Permalink
Merge pull request #452 from IndrajeetPatil/b382-path-ext
Browse files Browse the repository at this point in the history
`path_ext()` returns correct extension if multiple dots present
  • Loading branch information
gaborcsardi authored Apr 27, 2024
2 parents db53761 + 6285343 commit 342ac30
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 1 deletion.
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# fs (development version)

* `path_ext()` returns extension when multiple dots are present in file name (@IndrajeetPatil, #452).

# fs 1.6.4

* No changes.
Expand Down
2 changes: 1 addition & 1 deletion R/path.R
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ path_ext <- function(path) {
return(character())
}

res <- captures(path_file(path), regexpr("(?<!^|[.]|/)[.]([^.]+)$", path_file(path), perl = TRUE))[[1]]
res <- captures(path_file(path), regexpr("(?<!^|[.]|/)[.]+([^.]+)$", path_file(path), perl = TRUE))[[1]]
res[!is.na(path) & is.na(res)] <- ""
res
}
Expand Down
2 changes: 2 additions & 0 deletions tests/testthat/test-path.R
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,8 @@ describe("path_ext", {
expect_equal(path_ext(".cshrc"), "")
expect_equal(path_ext("...manydots"), "")
expect_equal(path_ext("...manydots.ext"), "ext")
expect_equal(path_ext("manydots..."), "")
expect_equal(path_ext("manydots...ext"), "ext")
expect_equal(path_ext("."), "")
expect_equal(path_ext(".."), "")
expect_equal(path_ext("........"), "")
Expand Down

0 comments on commit 342ac30

Please sign in to comment.