From d6e1745ee7559a30a88fca4f13763cdae13d3916 Mon Sep 17 00:00:00 2001 From: Zachary Scott Date: Sun, 26 Jun 2016 13:42:15 +0900 Subject: [PATCH] Use Mustermann internally for building `prefixed_path` as `RegexpBased` pattern Removed `regexpify` from internal API. --- sinatra-contrib/lib/sinatra/namespace.rb | 13 ++----------- sinatra-contrib/spec/namespace_spec.rb | 5 ++--- 2 files changed, 4 insertions(+), 14 deletions(-) diff --git a/sinatra-contrib/lib/sinatra/namespace.rb b/sinatra-contrib/lib/sinatra/namespace.rb index c0293fa0..f4213510 100644 --- a/sinatra-contrib/lib/sinatra/namespace.rb +++ b/sinatra-contrib/lib/sinatra/namespace.rb @@ -201,7 +201,7 @@ module Sinatra end def error(*codes, &block) - args = Sinatra::Base.send(:compile!, "ERROR", regexpify(@pattern), block) + args = Sinatra::Base.send(:compile!, "ERROR", @pattern, block) codes = codes.map { |c| Array(c) }.flatten codes << Exception if codes.empty? @@ -266,16 +266,7 @@ module Sinatra def prefixed_path(a, b) return a || b || // unless a and b - a, b = regexpify(a), regexpify(b) unless a.class == b.class - path = a.class.new "#{a}#{b}" - path = /^#{path}$/ if path.is_a? Regexp and base == app - path - end - - def regexpify(pattern) - pattern = Sinatra::Base.send(:compile, pattern).first.inspect - pattern.gsub! /^\/(\^|\\A)?|(\$|\\z)?\/$/, '' - Regexp.new pattern + Mustermann.new(a.to_s + b.to_s, type: :regular) end def prefixed(method, pattern = nil, conditions = {}, &block) diff --git a/sinatra-contrib/spec/namespace_spec.rb b/sinatra-contrib/spec/namespace_spec.rb index 8cdbcb1c..2a11c989 100644 --- a/sinatra-contrib/spec/namespace_spec.rb +++ b/sinatra-contrib/spec/namespace_spec.rb @@ -1,8 +1,7 @@ require 'spec_helper' describe Sinatra::Namespace do - verbs = [:get, :head, :post, :put, :delete, :options] - verbs << :patch if Sinatra::VERSION >= '1.3' + verbs = [:get, :head, :post, :put, :delete, :options, :patch] def mock_app(&block) super do @@ -689,7 +688,7 @@ describe Sinatra::Namespace do end get('/bar') { } end - route[1].should eq '/foo' + route[1].should eq Mustermann.new '/foo', type: :regular end specify 'prevent app-global settings from being changed' do