From d8cddf7479487d4e97bd76934f7af57488fda94a Mon Sep 17 00:00:00 2001 From: Yessiest Date: Sat, 15 Apr 2023 00:52:25 +0400 Subject: [PATCH] Pathspec functions correctly --- hyde.rb | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/hyde.rb b/hyde.rb index 59a3f40..20e3d27 100644 --- a/hyde.rb +++ b/hyde.rb @@ -8,14 +8,16 @@ module Hyde end def match?(path) raise Exception, "Not permitted" if @lock_methods - split_path = path.split("/") - puts "#{path}, #{@path}, #{normalize_input(path)}" + return true if @path == "" if @path.kind_of? Regexp then - anchored_regex = Regexp.new("^"+@path.to_s+"$") - return anchored_regex.match split_path[0] unless @full_regexp - return anchored_regex.match normalize_input(path) + return Regexp.new("^"+@path.to_s+"$").match normalize_input(path) else - return split_path[0] == @path + split_path = path.split("/").filter { |x| x != "" } + @path.split("/").filter { |x| x != "" } + .each_with_index { |x,i| + return false if x != split_path[i] + } + return true end end def normalize_input(path) @@ -24,8 +26,8 @@ module Hyde end def normalize(path) raise Exception, "Not permitted" if @lock_methods - # remove multiple slashes in one spot - path = (path.split "/").filter {|x| x != ""}.join("/") + # remove multiple slashes in one spot and trim edge slashes + path = normalize_input(path) # globbing behaviour simulated with regexp if path.match /(?