sinatra 2.0.0.rc2 → 2.0.0.rc5

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of sinatra might be problematic. Click here for more details.

checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: fd75c727db7b65c390511a4adeb420a6d8a93e18
4
- data.tar.gz: a0be265c79512e4f331270bf1fb71af08a06ee1f
3
+ metadata.gz: d2244e3562cbc37fb6ff2e06c56844417a7b0fb6
4
+ data.tar.gz: 06dd9dc2c62f8ac778dcb8e6cbe63bf76a5fa4d3
5
5
  SHA512:
6
- metadata.gz: f6de783030b6c39cd7d3f0bab6dc7789fc83d714c41f52f89a953014798dfcf4d8c98565a2df4ac53165d077a98c3431b448a89754a7b3a6d029eb83415df5c2
7
- data.tar.gz: 3bc6a1b14338af6e723bbdd07dd22ffed9058def429183be213df539cf5b3ec04bb021eb40adae0f66266c8883a827963e42f118ea8eeb4d16f65765111a1909
6
+ metadata.gz: cbbb5659a7e65970843c4ec9c890c3a42f3e5ac342ef56125e820fefb447a08d799f3f819eaf1da9a49723b86e4059ee1ae8c4f078d8f7d61838b1728bdabdd7
7
+ data.tar.gz: 3dd1a518d8de680db95f3b84151793404cc042cc40d4db910e3193eaec2b3fedf8fca1e71802fae866bc7e5173502ad32dd4eb2c0fffa81988c5e2e789d82c4c
@@ -1,4 +1,4 @@
1
- ## 2.0.0 / 2016-08-22
1
+ ## 2.0.0 / 2017-04-10
2
2
 
3
3
  * Use Mustermann for patterns #1086 by Konstantin Haase
4
4
 
@@ -36,6 +36,32 @@
36
36
 
37
37
  * Use same `session_secret` for classic and modular apps in development #1245 by Marcus Stollsteimer
38
38
 
39
+ * Make authenticity token length a fixed value of 32 #1181 by Jordan Owens
40
+
41
+ * Modernize Rack::Protection::ContentSecurityPolicy with CSP Level 2 and 3 Directives #1202 by Glenn Rempe
42
+
43
+ * Adds preload option to Rack:Protection:StrictTransport #1209 by Ed Robinson
44
+
45
+ * Improve BadRequest logic. Raise and handle exceptions if status is 400 #1212 by Mike Pastore
46
+
47
+ * Make Rack::Test a development dependency #1232 by Mike Pastore
48
+
49
+ * Capture exception messages of raised NotFound and BadRequest #1210 by Mike Pastore
50
+
51
+ * Add explicit set method to contrib/cookies to override cookie settings #1240 by Andrew Allen
52
+
53
+ * Avoid executing filters even if prefix matches with other namespace #1253 by namusyaka
54
+
55
+ * Make `#has_key?` also indifferent in access, can accept String or Symbol #1262 by John Hope
56
+
57
+ * Add `allow_if` option to bypass json csrf protection #1265 by Jordan Owens
58
+
59
+ * rack-protection: Bundle StrictTransport, CookieTossing, and CSP #1267 by Mike Pastore
60
+
61
+ * Add `:strict_paths` option for managing trailing slashes #1273 by namusyaka
62
+
63
+ * Add full IndifferentHash implementation to params #1279 by Mike Pastore
64
+
39
65
  ## 1.4.7 / 2016-01-24
40
66
 
41
67
  * Add Ashley Williams, Trevor Bramble, and Kashyap Kondamudi to team Sinatra.
data/Gemfile CHANGED
@@ -14,6 +14,7 @@ gem 'rake'
14
14
  gem 'rack', git: 'https://github.com/rack/rack.git'
15
15
  gem 'rack-test', '>= 0.6.2'
16
16
  gem "minitest", "~> 5.0"
17
+ gem 'yard'
17
18
 
18
19
  gem "rack-protection", path: "rack-protection"
19
20
  gem "sinatra-contrib", path: "sinatra-contrib"
data/Rakefile CHANGED
@@ -9,10 +9,7 @@ task :spec => :test
9
9
  CLEAN.include "**/*.rbc"
10
10
 
11
11
  def source_version
12
- @source_version ||= begin
13
- load './lib/sinatra/version.rb'
14
- Sinatra::VERSION
15
- end
12
+ @source_version ||= File.read(File.expand_path("../VERSION", __FILE__)).strip
16
13
  end
17
14
 
18
15
  def prev_feature
@@ -92,7 +89,7 @@ end
92
89
 
93
90
  team = ["Ryan Tomayko", "Blake Mizerany", "Simon Rozet", "Konstantin Haase", "Zachary Scott"]
94
91
  desc "list of contributors"
95
- task :thanks, [:release,:backports] do |t, a|
92
+ task :thanks, ['release:all', :backports] do |t, a|
96
93
  a.with_defaults :release => "#{prev_version}..HEAD",
97
94
  :backports => "#{prev_feature}.0..#{prev_feature}.x"
98
95
  included = `git log --format=format:"%aN\t%s" #{a.release}`.lines.map { |l| l.force_encoding('binary') }
@@ -141,54 +138,86 @@ end
141
138
  # PACKAGING ============================================================
142
139
 
143
140
  if defined?(Gem)
144
- # Load the gemspec using the same limitations as github
145
- def spec
146
- require 'rubygems' unless defined? Gem::Specification
147
- @spec ||= eval(File.read('sinatra.gemspec'))
141
+ GEMS_AND_ROOT_DIRECTORIES = {
142
+ "sinatra" => ".",
143
+ "sinatra-contrib" => "./sinatra-contrib",
144
+ "rack-protection" => "./rack-protection"
145
+ }
146
+
147
+ def package(gem, ext='')
148
+ "pkg/#{gem}-#{source_version}" + ext
148
149
  end
149
150
 
150
- def package(ext='')
151
- "pkg/sinatra-#{spec.version}" + ext
152
- end
151
+ directory 'pkg/'
152
+ CLOBBER.include('pkg')
153
153
 
154
- desc 'Build packages'
155
- task :package => %w[.gem .tar.gz].map {|e| package(e)}
154
+ GEMS_AND_ROOT_DIRECTORIES.each do |gem, directory|
155
+ file package(gem, '.gem') => ["pkg/", "#{directory + '/' + gem}.gemspec"] do |f|
156
+ sh "cd #{directory} && gem build #{gem}.gemspec"
157
+ mv directory + "/" + File.basename(f.name), f.name
158
+ end
156
159
 
157
- desc 'Build and install as local gem'
158
- task :install => package('.gem') do
159
- sh "gem install #{package('.gem')}"
160
+ file package(gem, '.tar.gz') => ["pkg/"] do |f|
161
+ sh <<-SH
162
+ git archive \
163
+ --prefix=#{gem}-#{source_version}/ \
164
+ --format=tar \
165
+ HEAD -- #{directory} | gzip > #{f.name}
166
+ SH
167
+ end
160
168
  end
161
169
 
162
- directory 'pkg/'
163
- CLOBBER.include('pkg')
170
+ namespace :package do
171
+ GEMS_AND_ROOT_DIRECTORIES.each do |gem, directory|
172
+ desc "Build #{gem} packages"
173
+ task gem => %w[.gem .tar.gz].map { |e| package(gem, e) }
174
+ end
164
175
 
165
- file package('.gem') => %w[pkg/ sinatra.gemspec] + spec.files do |f|
166
- sh "gem build sinatra.gemspec"
167
- mv File.basename(f.name), f.name
176
+ desc "Build all packages"
177
+ task :all => GEMS_AND_ROOT_DIRECTORIES.keys
168
178
  end
169
179
 
170
- file package('.tar.gz') => %w[pkg/] + spec.files do |f|
171
- sh <<-SH
172
- git archive \
173
- --prefix=sinatra-#{source_version}/ \
174
- --format=tar \
175
- HEAD | gzip > #{f.name}
176
- SH
180
+ namespace :install do
181
+ GEMS_AND_ROOT_DIRECTORIES.each do |gem, directory|
182
+ desc "Build and install #{gem} as local gem"
183
+ task gem => package(gem, '.gem') do
184
+ sh "gem install #{package(gem, '.gem')}"
185
+ end
186
+ end
187
+
188
+ desc "Build and install all of the gems as local gems"
189
+ task :all => GEMS_AND_ROOT_DIRECTORIES.keys
177
190
  end
178
191
 
179
- task 'release' => ['test', package('.gem')] do
180
- if File.binread("CHANGELOG.md") =~ /= \d\.\d\.\d . not yet released$/i
181
- fail 'please update the changelog first' unless %x{git symbolic-ref HEAD} == "refs/heads/prerelease\n"
192
+ namespace :release do
193
+ GEMS_AND_ROOT_DIRECTORIES.each do |gem, directory|
194
+ desc "Release #{gem} as a package"
195
+ task gem => "package:#{gem}" do
196
+ sh <<-SH
197
+ gem install #{package(gem, '.gem')} --local &&
198
+ gem push #{package(gem, '.gem')}
199
+ SH
200
+ end
201
+ end
202
+
203
+ desc "Commits the version to github repository"
204
+ task :commit_version do
205
+ sh <<-SH
206
+ sed -i "s/.*VERSION.*/ VERSION = '#{source_version}'/" lib/sinatra/version.rb
207
+ sed -i "s/.*VERSION.*/ VERSION = '#{source_version}'/" sinatra-contrib/lib/sinatra/contrib/version.rb
208
+ sed -i "s/.*VERSION.*/ VERSION = '#{source_version}'/" rack-protection/lib/rack/protection/version.rb
209
+ SH
210
+
211
+ sh <<-SH
212
+ git commit --allow-empty -a -m '#{source_version} release' &&
213
+ git tag -s v#{source_version} -m '#{source_version} release' &&
214
+ git tag -s #{source_version} -m '#{source_version} release' &&
215
+ git push && (git push origin || true) &&
216
+ git push --tags && (git push origin --tags || true)
217
+ SH
182
218
  end
183
219
 
184
- sh <<-SH
185
- gem install #{package('.gem')} --local &&
186
- gem push #{package('.gem')} &&
187
- git commit --allow-empty -a -m '#{source_version} release' &&
188
- git tag -s v#{source_version} -m '#{source_version} release' &&
189
- git tag -s #{source_version} -m '#{source_version} release' &&
190
- git push && (git push sinatra || true) &&
191
- git push --tags && (git push sinatra --tags || true)
192
- SH
220
+ desc "Release all gems as packages"
221
+ task :all => [:test, :commit_version] + GEMS_AND_ROOT_DIRECTORIES.keys
193
222
  end
194
223
  end
@@ -15,6 +15,7 @@ require 'time'
15
15
  require 'uri'
16
16
 
17
17
  # other files we need
18
+ require 'sinatra/indifferent_hash'
18
19
  require 'sinatra/show_exceptions'
19
20
  require 'sinatra/version'
20
21
 
@@ -240,18 +241,6 @@ module Sinatra
240
241
  def http_status; 404 end
241
242
  end
242
243
 
243
- class IndifferentHash < Hash
244
- def [](key)
245
- value = super(key)
246
- return super(key.to_s) if value.nil? && Symbol === key
247
- value
248
- end
249
-
250
- def has_key?(key)
251
- super(key) || (Symbol === key && super(key.to_s))
252
- end
253
- end
254
-
255
244
  # Methods available to routes, before/after filters, and views.
256
245
  module Helpers
257
246
  # Set or retrieve the response status code.
@@ -1029,6 +1018,7 @@ module Sinatra
1029
1018
  def process_route(pattern, conditions, block = nil, values = [])
1030
1019
  route = @request.path_info
1031
1020
  route = '/' if route.empty? and not settings.empty_path_info?
1021
+ route = route[0..-2] if !settings.strict_paths? && route != '/' && route.end_with?('/')
1032
1022
  return unless params = pattern.params(route)
1033
1023
 
1034
1024
  params.delete("ignore") # TODO: better params handling, maybe turn it into "smart" object or detect changes
@@ -1078,20 +1068,6 @@ module Sinatra
1078
1068
  send_file path, options.merge(:disposition => nil)
1079
1069
  end
1080
1070
 
1081
- # Enable string or symbol key access to the nested params hash.
1082
- def indifferent_params(object)
1083
- case object
1084
- when Hash
1085
- new_hash = IndifferentHash.new
1086
- object.each { |key, value| new_hash[key] = indifferent_params(value) }
1087
- new_hash
1088
- when Array
1089
- object.map { |item| indifferent_params(item) }
1090
- else
1091
- object
1092
- end
1093
- end
1094
-
1095
1071
  # Run the block with 'throw :halt' support and apply result to the response.
1096
1072
  def invoke
1097
1073
  res = catch(:halt) { yield }
@@ -1110,8 +1086,7 @@ module Sinatra
1110
1086
 
1111
1087
  # Dispatch a request with error handling.
1112
1088
  def dispatch!
1113
- @params = indifferent_params(@request.params)
1114
- force_encoding(@params)
1089
+ force_encoding(@params = IndifferentHash[@request.params])
1115
1090
 
1116
1091
  invoke do
1117
1092
  static! if settings.static? && (request.get? || request.head?)
@@ -1845,6 +1820,7 @@ module Sinatra
1845
1820
  set :absolute_redirects, true
1846
1821
  set :prefixed_redirects, false
1847
1822
  set :empty_path_info, nil
1823
+ set :strict_paths, true
1848
1824
 
1849
1825
  set :app_file, nil
1850
1826
  set :root, Proc.new { app_file && File.expand_path(File.dirname(app_file)) }
@@ -0,0 +1,150 @@
1
+ # frozen_string_literal: true
2
+ module Sinatra
3
+ # A poor man's ActiveSupport::HashWithIndifferentAccess, with all the Rails-y
4
+ # stuff removed.
5
+ #
6
+ # Implements a hash where keys <tt>:foo</tt> and <tt>"foo"</tt> are
7
+ # considered to be the same.
8
+ #
9
+ # rgb = Sinatra::IndifferentHash.new
10
+ #
11
+ # rgb[:black] = '#000000' # symbol assignment
12
+ # rgb[:black] # => '#000000' # symbol retrieval
13
+ # rgb['black'] # => '#000000' # string retrieval
14
+ #
15
+ # rgb['white'] = '#FFFFFF' # string assignment
16
+ # rgb[:white] # => '#FFFFFF' # symbol retrieval
17
+ # rgb['white'] # => '#FFFFFF' # string retrieval
18
+ #
19
+ # Internally, symbols are mapped to strings when used as keys in the entire
20
+ # writing interface (calling e.g. <tt>[]=</tt>, <tt>merge</tt>). This mapping
21
+ # belongs to the public interface. For example, given:
22
+ #
23
+ # hash = Sinatra::IndifferentHash.new(:a=>1)
24
+ #
25
+ # You are guaranteed that the key is returned as a string:
26
+ #
27
+ # hash.keys # => ["a"]
28
+ #
29
+ # Technically other types of keys are accepted:
30
+ #
31
+ # hash = Sinatra::IndifferentHash.new(:a=>1)
32
+ # hash[0] = 0
33
+ # hash # => { "a"=>1, 0=>0 }
34
+ #
35
+ # But this class is intended for use cases where strings or symbols are the
36
+ # expected keys and it is convenient to understand both as the same. For
37
+ # example the +params+ hash in Sinatra.
38
+ class IndifferentHash < Hash
39
+ def self.[](*args)
40
+ new.merge!(Hash[*args])
41
+ end
42
+
43
+ def initialize(*args)
44
+ super(*args.map(&method(:convert_value)))
45
+ end
46
+
47
+ def default(*args)
48
+ super(*args.map(&method(:convert_key)))
49
+ end
50
+
51
+ def default=(value)
52
+ super(convert_value(value))
53
+ end
54
+
55
+ def assoc(key)
56
+ super(convert_key(key))
57
+ end
58
+
59
+ def rassoc(value)
60
+ super(convert_value(value))
61
+ end
62
+
63
+ def fetch(key, *args)
64
+ super(convert_key(key), *args.map(&method(:convert_value)))
65
+ end
66
+
67
+ def [](key)
68
+ super(convert_key(key))
69
+ end
70
+
71
+ def []=(key, value)
72
+ super(convert_key(key), convert_value(value))
73
+ end
74
+
75
+ alias_method :store, :[]=
76
+
77
+ def key(value)
78
+ super(convert_value(value))
79
+ end
80
+
81
+ def key?(key)
82
+ super(convert_key(key))
83
+ end
84
+
85
+ alias_method :has_key?, :key?
86
+ alias_method :include?, :key?
87
+ alias_method :member?, :key?
88
+
89
+ def value?(value)
90
+ super(convert_value(value))
91
+ end
92
+
93
+ alias_method :has_value?, :value?
94
+
95
+ def delete(key)
96
+ super(convert_key(key))
97
+ end
98
+
99
+ def dig(key, *other_keys)
100
+ super(convert_key(key), *other_keys)
101
+ end if method_defined?(:dig) # Added in Ruby 2.3
102
+
103
+ def fetch_values(*keys)
104
+ super(*keys.map(&method(:convert_key)))
105
+ end if method_defined?(:fetch_values) # Added in Ruby 2.3
106
+
107
+ def values_at(*keys)
108
+ super(*keys.map(&method(:convert_key)))
109
+ end
110
+
111
+ def merge!(other_hash)
112
+ return super if other_hash.is_a?(self.class)
113
+
114
+ other_hash.each_pair do |key, value|
115
+ key = convert_key(key)
116
+ value = yield(key, self[key], value) if block_given? && key?(key)
117
+ self[key] = convert_value(value)
118
+ end
119
+
120
+ self
121
+ end
122
+
123
+ alias_method :update, :merge!
124
+
125
+ def merge(other_hash, &block)
126
+ dup.merge!(other_hash, &block)
127
+ end
128
+
129
+ def replace(other_hash)
130
+ super(other_hash.is_a?(self.class) ? other_hash : self.class[other_hash])
131
+ end
132
+
133
+ private
134
+
135
+ def convert_key(key)
136
+ key.is_a?(Symbol) ? key.to_s : key
137
+ end
138
+
139
+ def convert_value(value)
140
+ case value
141
+ when Hash
142
+ value.is_a?(self.class) ? value : self.class[value]
143
+ when Array
144
+ value.map(&method(:convert_value))
145
+ else
146
+ value
147
+ end
148
+ end
149
+ end
150
+ end
@@ -1,3 +1,3 @@
1
1
  module Sinatra
2
- VERSION = '2.0.0.rc2'
2
+ VERSION = '2.0.0.rc5'
3
3
  end
@@ -1,7 +1,6 @@
1
- $LOAD_PATH.unshift File.expand_path('../lib', __FILE__)
2
- require 'sinatra/version'
1
+ version = File.read(File.expand_path("../VERSION", __FILE__)).strip
3
2
 
4
- Gem::Specification.new 'sinatra', Sinatra::VERSION do |s|
3
+ Gem::Specification.new 'sinatra', version do |s|
5
4
  s.description = "Sinatra is a DSL for quickly creating web applications in Ruby with minimal effort."
6
5
  s.summary = "Classy web-development dressed in a DSL"
7
6
  s.authors = ["Blake Mizerany", "Ryan Tomayko", "Simon Rozet", "Konstantin Haase"]
@@ -27,6 +26,6 @@ Gem::Specification.new 'sinatra', Sinatra::VERSION do |s|
27
26
 
28
27
  s.add_dependency 'rack', '~> 2.0'
29
28
  s.add_dependency 'tilt', '~> 2.0'
30
- s.add_dependency 'rack-protection', '2.0.0.rc2'
31
- s.add_dependency 'mustermann', '1.0.0'
29
+ s.add_dependency 'rack-protection', version
30
+ s.add_dependency 'mustermann', '~> 1.0'
32
31
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sinatra
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0.rc2
4
+ version: 2.0.0.rc5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Blake Mizerany
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2017-03-19 00:00:00.000000000 Z
14
+ date: 2017-05-06 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: rack
@@ -47,28 +47,28 @@ dependencies:
47
47
  requirements:
48
48
  - - '='
49
49
  - !ruby/object:Gem::Version
50
- version: 2.0.0.rc2
50
+ version: 2.0.0.rc5
51
51
  type: :runtime
52
52
  prerelease: false
53
53
  version_requirements: !ruby/object:Gem::Requirement
54
54
  requirements:
55
55
  - - '='
56
56
  - !ruby/object:Gem::Version
57
- version: 2.0.0.rc2
57
+ version: 2.0.0.rc5
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: mustermann
60
60
  requirement: !ruby/object:Gem::Requirement
61
61
  requirements:
62
- - - '='
62
+ - - "~>"
63
63
  - !ruby/object:Gem::Version
64
- version: 1.0.0
64
+ version: '1.0'
65
65
  type: :runtime
66
66
  prerelease: false
67
67
  version_requirements: !ruby/object:Gem::Requirement
68
68
  requirements:
69
- - - '='
69
+ - - "~>"
70
70
  - !ruby/object:Gem::Version
71
- version: 1.0.0
71
+ version: '1.0'
72
72
  description: Sinatra is a DSL for quickly creating web applications in Ruby with minimal
73
73
  effort.
74
74
  email: sinatrarb@googlegroups.com
@@ -115,6 +115,7 @@ files:
115
115
  - lib/sinatra/base.rb
116
116
  - lib/sinatra/images/404.png
117
117
  - lib/sinatra/images/500.png
118
+ - lib/sinatra/indifferent_hash.rb
118
119
  - lib/sinatra/main.rb
119
120
  - lib/sinatra/show_exceptions.rb
120
121
  - lib/sinatra/version.rb
@@ -146,7 +147,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
146
147
  version: 1.3.1
147
148
  requirements: []
148
149
  rubyforge_project:
149
- rubygems_version: 2.6.8
150
+ rubygems_version: 2.6.11
150
151
  signing_key:
151
152
  specification_version: 4
152
153
  summary: Classy web-development dressed in a DSL