mirror of
https://github.com/sinatra/sinatra
synced 2023-03-27 23:18:01 -04:00
fix decompile for sinatra 1.4
This commit is contained in:
parent
7582bb9635
commit
140dea2f09
1 changed files with 12 additions and 5 deletions
|
@ -70,18 +70,25 @@ module Sinatra
|
|||
def decompile(pattern, keys = nil, *)
|
||||
# Everything in here is basically just the reverse of
|
||||
# Sinatra::Base#compile
|
||||
#
|
||||
# Sinatra 2.0 will come with a mechanism for this, making this obsolete.
|
||||
pattern, keys = pattern if pattern.respond_to? :to_ary
|
||||
keys, str = keys.try(:dup), pattern.inspect
|
||||
return pattern unless str.start_with? '/' and str.end_with? '/'
|
||||
str.gsub! /^\/\^?|\$?\/$/, ''
|
||||
str.gsub! /^\/(\^|\\A)?|(\$|\\z)?\/$/, ''
|
||||
str.gsub! encoded(' '), ' '
|
||||
return pattern if str =~ /^[\.\+]/
|
||||
str.gsub! /\([^\(\)]*\)/ do |part|
|
||||
capture = '((?:[^\.\/?#%]|(?:%[^2].|%[2][^Ee]))+)'
|
||||
str.gsub! /\([^\(\)]*\)|\([^\(\)]*\([^\(\)]*\)[^\(\)]*\)|#{Regexp.escape(capture)}/ do |part|
|
||||
case part
|
||||
when '(.*?)'
|
||||
return pattern if keys.shift != 'splat'
|
||||
'*'
|
||||
when '([^\/?#]+)'
|
||||
when /^\(\?\:(\\*.)\|%[\w\[\]]+\)$/
|
||||
$1
|
||||
when /^\(\?\:(%\d+)\|([^\)]+|\([^\)]+\))\)$/
|
||||
URI.unescape($1)
|
||||
when '([^\/?#]+)', capture
|
||||
return pattern if keys.empty?
|
||||
":" << keys.shift
|
||||
when /^\(\?\:\\?(.)\|/
|
||||
|
@ -102,8 +109,8 @@ module Sinatra
|
|||
|
||||
def encoded(char)
|
||||
return super if defined? super
|
||||
enc = URI.encode(char)
|
||||
enc = "(?:#{Regexp.escape enc}|#{URI.encode char, /./})" if enc == char
|
||||
enc = URI.escape(char)
|
||||
enc = "(?:#{escaped(char, enc).join('|')})" if enc == char
|
||||
enc = "(?:#{enc}|#{encoded('+')})" if char == " "
|
||||
enc
|
||||
end
|
||||
|
|
Loading…
Add table
Reference in a new issue