Skip to content

Commit

Permalink
lint a random file (#3563)
Browse files Browse the repository at this point in the history
  • Loading branch information
osc-bot authored May 20, 2024
1 parent 75ea435 commit 18d26b4
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions apps/myjobs/app/models/whitelist_policy.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

class WhitelistPolicy
attr_reader :whitelist

Expand All @@ -8,18 +10,17 @@ def initialize(whitelist)
# @raises ArgumentError if any whitelist path or permitted? argument
# has the form ~user/some/path where user doesn't exist
def permitted?(path)
whitelist.blank? || whitelist.any?{ |parent| child?(Pathname.new(parent), real_expanded_path(path)) }
whitelist.blank? || whitelist.any? { |parent| child?(Pathname.new(parent), real_expanded_path(path)) }
end

# call realpath to ensure symlinks are handled
def real_expanded_path(path)
# call realpath to ensure symlinks are resolved
Pathname.new(path).expand_path.realpath
rescue SystemCallError
# path doesn't exist, so we just get absolute version then
Pathname.new(path).expand_path
end

def real_expanded_path(path)
# call realpath to ensure symlinks are resolved
Pathname.new(path).expand_path.realpath
rescue SystemCallError
# path doesn't exist, so we just get absolute version then
Pathname.new(path).expand_path
end

# Determine if child is a subpath of parent
#
Expand All @@ -30,7 +31,7 @@ def real_expanded_path(path)
# @param child [Pathname]
# @return Boolean
def child?(parent, child)
! child.expand_path.relative_path_from(
!child.expand_path.relative_path_from(
parent.expand_path
).each_filename.to_a.include?(
'..'
Expand Down

0 comments on commit 18d26b4

Please sign in to comment.