Skip to content

Commit

Permalink
fix trailing "**" and add respective tests
Browse files Browse the repository at this point in the history
  • Loading branch information
hhaensel committed Jun 5, 2024
1 parent 88048da commit ba9dc2b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/Glob.jl
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ function occursin(fn::FilenameMatch, s::AbstractString)
noescape = (fn.options & NOESCAPE) != 0
pathname = (fn.options & PATHNAME) != 0
extended = (fn.options & EXTENDED) != 0

pathname && endswith(pattern, "**") && (pattern *= "/*")

mi = firstindex(pattern) # current index into pattern
i = firstindex(s) # current index into s
starmatch = i
Expand Down
11 changes: 11 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,17 @@ end
@test !occursin(fn"/**/*.png"d, "a/c.png")
@test !occursin(fn"/**/*.png"d, "a/b/c.png")

@test occursin(fn"**.png"d, "c.png")
@test !occursin(fn"**.png"d, "a/b/c.png")

@test occursin(fn"**"d, "c.png")
@test occursin(fn"**"d, "a/c.png")
@test occursin(fn"**"d, "/a/c.png")
@test occursin(fn"/**"d, "/a/c.png")
@test occursin(fn"/a/**"d, "/a/c.png")
@test !occursin(fn"/b/**"d, "/a/c.png")
@test !occursin(fn"/**"d, "a/c.png")

function test_string(x1)
x2 = string(eval(Meta.parse(x1)))
x1 == x2 ? nothing : error(string(
Expand Down

0 comments on commit ba9dc2b

Please sign in to comment.