diff --git a/hyde.rb b/hyde.rb index 32bf320..1c06088 100644 --- a/hyde.rb +++ b/hyde.rb @@ -1,9 +1,10 @@ require 'mime-types' require 'webrick' +require 'uri' module Hyde # Branding and version - VERSION = "0.1" + VERSION = "0.5 (alpha)" attr_reader :VERSION VLINE = "
\n Hyde/#{Hyde::VERSION} on WEBrick/#{WEBrick::VERSION} (Ruby/#{RUBY_VERSION}/#{RUBY_RELEASE_DATE})\n " attr_reader :VLINE @@ -13,7 +14,14 @@ module Hyde super(config) @hyde_pathspec = Hyde::Pathspec.new "/", &setup self.mount_proc '/' do |req,res| - @hyde_pathspec.match(Hyde::Context.new(req.path, req, res)) + context = Hyde::Context.new(req.path, req, res) + while context and (not context.exit_loop) do + context.exit_loop = true + context = catch :controlled_exit do + @hyde_pathspec._match(context) + context + end + end end end end @@ -36,14 +44,12 @@ module Hyde # Interchangeable glob/regex/string pattern matching module PatternMatching - def prep_path(path,match_full_path: false) - raise Exception, "Not permitted" if @lock_methods - @match_full_path = match_full_path - @path = normalize(path) if path.kind_of? String + def _prep_path(path,safe_regexp: true) + @safe_regexp = safe_regexp + @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 + def _match?(path) # behvaiour used by "index" method return true if @path == "" split_path = path.split("/").filter { |x| x != "" } @@ -51,10 +57,10 @@ module Hyde # this chunk of fuck is needed to force regexp into 3 rules: # 1) unsafe regexp means match the whole (remaining) line. # 3) safe regexp means match only the part before the next slash - # 2) a .match? only returns when there are no leftovers + # 2) a ._match? only returns when there are no leftovers # this forces the matching to work somewhat consistently - test = @path.match normalize_input(path) if @match_full_path - test = @path.match split_path[0] unless @match_full_path + test = @path.match _normalize_input(path) unless @safe_regexp + test = @path.match split_path[0] if @safe_regexp if test and (test.pre_match == "") and (test.post_match == "") then return true else @@ -69,15 +75,13 @@ module Hyde return true end end - def normalize_input(path) - raise Exception, "Not permitted" if @lock_methods + def _normalize_input(path) # remove duplicate slashes and trim edge slashes (path.split "/").filter { |x| x != "" }.join("/") end - def normalize(path) - raise Exception, "Not permitted" if @lock_methods - # remove duplicate slashes and trim edge slashes - path = normalize_input(path) + def _normalize(path) + # remove duplicate slashe s and trim edge slashes + path = _normalize_input(path) # globbing behaviour simulated with regexp if path.match /(?#{url}.