Skip to content

Commit

Permalink
Use start_with?
Browse files Browse the repository at this point in the history
  • Loading branch information
robinkar committed Sep 20, 2024
1 parent e78b2df commit 52dc17f
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 deletions apps/dashboard/app/models/allowlist_policy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,7 @@ def child?(parent, child)
# Expand both paths to evaluate any potential ".." components to be able to compare them as strings.
p = parent.expand_path.to_s
c = child.expand_path.to_s
# Child path shorter than parent => not a child.
return false if c.size < p.size
# Child path is same as parent path, or has additional components after parent path (has "/" after parent path).
c[0...p.size] == p && (c.size == p.size || c[p.size] == "/")
# Child path if it is same as parent path, or has additional components after "/".
c.start_with?(p) && (c.size == p.size || c[p.size] == "/")
end
end

0 comments on commit 52dc17f

Please sign in to comment.