From b006e0f672bb596c4102cbb021c8a0f400507e48 Mon Sep 17 00:00:00 2001 From: Yessiest Date: Wed, 12 Apr 2023 15:42:07 +0400 Subject: [PATCH] yes 2 --- hyde.rb | 106 ++++++++++++++++++++++++++++++++++++++++++++------- test_hyde.rb | 17 +++++++++ 2 files changed, 109 insertions(+), 14 deletions(-) create mode 100644 test_hyde.rb diff --git a/hyde.rb b/hyde.rb index 1937b93..59a3f40 100644 --- a/hyde.rb +++ b/hyde.rb @@ -1,33 +1,111 @@ module Hyde - class Servlet - def initialize (path, &block_optional) - + # Interchangeable pattern matching + module PatternMatching + def prep_path(path) + raise Exception, "Not permitted" if @lock_methods + @path = normalize(path) if path.kind_of? String + @path = path if path.kind_of? Regexp + end + def match?(path) + raise Exception, "Not permitted" if @lock_methods + split_path = path.split("/") + puts "#{path}, #{@path}, #{normalize_input(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) + else + return split_path[0] == @path + end + end + def normalize_input(path) + raise Exception, "Not permitted" if @lock_methods + (path.split "/").filter { |x| x != "" }.join("/") + end + def normalize(path) + raise Exception, "Not permitted" if @lock_methods + # remove multiple slashes in one spot + path = (path.split "/").filter {|x| x != ""}.join("/") + # globbing behaviour simulated with regexp + if path.match /(?