sinatra 1.3.3 → 1.3.4

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.

data/AUTHORS CHANGED
@@ -1,8 +1,11 @@
1
1
  Sinatra was designed and developed by Blake Mizerany (bmizerany) in
2
- California. Continued development would not be possible without the ongoing
3
- financial support provided by [Heroku](http://heroku.com) and the emotional
4
- support provided by Adam Wiggins (adamwiggins) of Heroku, Chris Wanstrath (defunkt),
5
- PJ Hyett (pjhyett), and the rest of the GitHub crew.
2
+ California.
3
+
4
+ Sinatra would not have been possible without strong company backing.
5
+ In the past, financial and emotional support have been provided mainly by
6
+ [Heroku](http://heroku.com), [GitHub](http://github.com) and
7
+ [Engine Yard](http://www.engineyard.com/), and is now taken care of by
8
+ [Travis CI](http://travis-ci.com/).
6
9
 
7
10
  Special thanks to the following extraordinary individuals, who-out which
8
11
  Sinatra would not be possible:
data/CHANGES CHANGED
@@ -1,3 +1,20 @@
1
+ = 1.3.4 / 2012-01-26
2
+
3
+ * Improve documentation. (Kashyap, Stanislav Chistenko, Konstantin Haase,
4
+ ymmtmsys, Anurag Priyam)
5
+
6
+ * Adjustments to template system to work with Tilt edge. (Konstantin Haase)
7
+
8
+ * Fix streaming with latest Rack release. (Konstantin Haase)
9
+
10
+ * Fix default content type for Sinatra::Response with latest Rack release.
11
+ (Konstantin Haase)
12
+
13
+ * Fix regression where + was no longer treated like space. (Ross Boucher)
14
+
15
+ * Status, headers and body will be set correctly in an after filter when using
16
+ halt in a before filter or route. (Konstantin Haase)
17
+
1
18
  = 1.3.3 / 2012-08-19
2
19
 
3
20
  * Improved documentation. (burningTyger, Konstantin Haase, Gabriel Andretta,
@@ -9,9 +26,9 @@
9
26
  clients closing the connection. (Konstantin Haase)
10
27
 
11
28
  * Fix bug where having a query param and a URL param by the same name would
12
- concatinate the two values. (Konstantin Haase)
29
+ concatenate the two values. (Konstantin Haase)
13
30
 
14
- * Prevent douplicated log output when application is already wrapped in a
31
+ * Prevent duplicated log output when application is already wrapped in a
15
32
  `Rack::CommonLogger`. (Konstantin Haase)
16
33
 
17
34
  * Fix issue where `Rack::Link` and Rails were preventing indefinite streaming.
@@ -25,6 +42,9 @@
25
42
  * When protecting against CSRF attacks, drop the session instead of refusing
26
43
  the request. (Konstantin Haase)
27
44
 
45
+ * Status, headers and body will be set correctly in an after filter when using
46
+ halt in a before filter or route. (Konstantin Haase)
47
+
28
48
  = 1.3.2 / 2011-12-30
29
49
 
30
50
  * Don't automatically add `Rack::CommonLogger` if `Rack::Server` is adding it,
@@ -867,18 +867,33 @@ the stream object, allowing you to close it at any later point in the
867
867
  execution flow. This only works on evented servers, like Thin and Rainbows.
868
868
  Other servers will still close the stream:
869
869
 
870
+ # long polling
871
+
870
872
  set :server, :thin
871
873
  connections = []
872
874
 
873
- get '/' do
874
- # keep stream open
875
+ get '/subscribe' do
876
+ # register a client's interest in server events
875
877
  stream(:keep_open) { |out| connections << out }
878
+
879
+ # purge dead connections
880
+ connections.reject!(&:closed?)
881
+
882
+ # acknowledge
883
+ "subscribed"
876
884
  end
877
885
 
878
- post '/' do
879
- # write to all open streams
880
- connections.each { |out| out << params[:message] << "\n" }
881
- "message sent"
886
+ post '/message' do
887
+ connections.each do |out|
888
+ # notify client that a new message has arrived
889
+ out << message << "\n"
890
+
891
+ # indicate client to connect again
892
+ out.close
893
+ end
894
+
895
+ # acknowledge
896
+ "message received"
882
897
  end
883
898
 
884
899
  === Logging
@@ -1111,7 +1126,7 @@ error handlers) through the <tt>request</tt> method:
1111
1126
  request.host # "example.com"
1112
1127
  request.get? # true (similar methods for other verbs)
1113
1128
  request.form_data? # false
1114
- request["SOME_HEADER"] # value of SOME_HEADER header
1129
+ request["some_param"] # value of some_param parameter. [] is a shortcut to the params hash.
1115
1130
  request.referrer # the referrer of the client or '/'
1116
1131
  request.user_agent # user agent (used by :agent condition)
1117
1132
  request.cookies # hash of browser cookies
@@ -1281,8 +1296,8 @@ You can access those options via <tt>settings</tt>:
1281
1296
 
1282
1297
  Sinatra is using
1283
1298
  {Rack::Protection}[https://github.com/rkh/rack-protection#readme] to defend
1284
- you application against common, opportunistic attacks. You can easily disable
1285
- this behavior (which will open your application to tons of common
1299
+ your application against common, opportunistic attacks. You can easily disable
1300
+ this behavior (which will open up your application to tons of common
1286
1301
  vulnerabilities):
1287
1302
 
1288
1303
  disable :protection
@@ -1640,7 +1655,7 @@ Start with:
1640
1655
 
1641
1656
  Or with a <tt>config.ru</tt>, which allows using any Rack handler:
1642
1657
 
1643
- # config.ru
1658
+ # config.ru (run with rackup)
1644
1659
  require './my_app'
1645
1660
  run MyApp
1646
1661
 
@@ -1724,7 +1739,7 @@ assign them to a constant, you can do this with <tt>Sinatra.new</tt>:
1724
1739
 
1725
1740
  It takes the application to inherit from as optional argument:
1726
1741
 
1727
- # config.ru
1742
+ # config.ru (run with rackup)
1728
1743
  require 'sinatra/base'
1729
1744
 
1730
1745
  controller = Sinatra.new do
@@ -997,7 +997,7 @@ Thin - это более производительный и функциона
997
997
  request.host # "example.com"
998
998
  request.get? # true (есть аналоги для других методов HTTP)
999
999
  request.form_data? # false
1000
- request["SOME_HEADER"] # значение заголовка SOME_HEADER
1000
+ request["some_param"] # значение параметра some_param. Шорткат для хеша params
1001
1001
  request.referrer # источник запроса клиента либо '/'
1002
1002
  request.user_agent # user agent (используется для :agent условия)
1003
1003
  request.cookies # хеш, содержащий cookies браузера
@@ -63,6 +63,11 @@ module Sinatra
63
63
  # http://rack.rubyforge.org/doc/classes/Rack/Response.html
64
64
  # http://rack.rubyforge.org/doc/classes/Rack/Response/Helpers.html
65
65
  class Response < Rack::Response
66
+ def initialize(*)
67
+ super
68
+ headers['Content-Type'] ||= 'text/html'
69
+ end
70
+
66
71
  def body=(value)
67
72
  value = value.body while Rack::Response === value
68
73
  @body = String === value ? [value.to_str] : value
@@ -73,19 +78,39 @@ module Sinatra
73
78
  end
74
79
 
75
80
  def finish
76
- if status.to_i / 100 == 1
81
+ result = body
82
+
83
+ if drop_content_info?
77
84
  headers.delete "Content-Length"
78
85
  headers.delete "Content-Type"
79
- elsif Array === body and not [204, 304].include?(status.to_i)
86
+ end
87
+
88
+ if drop_body?
89
+ close
90
+ result = []
91
+ end
92
+
93
+ if calculate_content_length?
80
94
  # if some other code has already set Content-Length, don't muck with it
81
95
  # currently, this would be the static file-handler
82
- headers["Content-Length"] ||= body.inject(0) { |l, p| l + Rack::Utils.bytesize(p) }.to_s
96
+ headers["Content-Length"] = body.inject(0) { |l, p| l + Rack::Utils.bytesize(p) }.to_s
83
97
  end
84
98
 
85
- # Rack::Response#finish sometimes returns self as response body. We don't want that.
86
- status, headers, result = super
87
- result = body if result == self
88
- [status, headers, result]
99
+ [status.to_i, header, result]
100
+ end
101
+
102
+ private
103
+
104
+ def calculate_content_length?
105
+ headers["Content-Type"] and not headers["Content-Length"] and Array === body
106
+ end
107
+
108
+ def drop_content_info?
109
+ status.to_i / 100 == 1 or drop_body?
110
+ end
111
+
112
+ def drop_body?
113
+ [204, 205, 304].include?(status.to_i)
89
114
  end
90
115
  end
91
116
 
@@ -288,7 +313,7 @@ module Sinatra
288
313
  # Class of the response body in case you use #stream.
289
314
  #
290
315
  # Three things really matter: The front and back block (back being the
291
- # blog generating content, front the one sending it to the client) and
316
+ # block generating content, front the one sending it to the client) and
292
317
  # the scheduler, integrating with whatever concurrency feature the Rack
293
318
  # handler is using.
294
319
  #
@@ -860,7 +885,7 @@ module Sinatra
860
885
  route = @request.path_info
861
886
  route = '/' if route.empty? and not settings.empty_path_info?
862
887
  return unless match = pattern.match(route)
863
- values += match.captures.to_a.map { |v| force_encoding URI.decode(v) if v }
888
+ values += match.captures.to_a.map { |v| force_encoding URI.decode_www_form_component(v) if v }
864
889
 
865
890
  if values.any?
866
891
  original, @params = params, params.merge('splat' => [], 'captures' => values)
@@ -927,15 +952,18 @@ module Sinatra
927
952
  elsif res.respond_to? :each
928
953
  body res
929
954
  end
955
+ nil # avoid double setting the same response tuple twice
930
956
  end
931
957
 
932
958
  # Dispatch a request with error handling.
933
959
  def dispatch!
934
- static! if settings.static? && (request.get? || request.head?)
935
- filter! :before
936
- route!
960
+ invoke do
961
+ static! if settings.static? && (request.get? || request.head?)
962
+ filter! :before
963
+ route!
964
+ end
937
965
  rescue ::Exception => boom
938
- handle_exception!(boom)
966
+ invoke { handle_exception!(boom) }
939
967
  ensure
940
968
  filter! :after unless env['sinatra.static_file']
941
969
  end
@@ -1,3 +1,3 @@
1
1
  module Sinatra
2
- VERSION = '1.3.3'
2
+ VERSION = '1.3.4'
3
3
  end
@@ -12,7 +12,7 @@ Gem::Specification.new 'sinatra', Sinatra::VERSION do |s|
12
12
  s.extra_rdoc_files = s.files.select { |p| p =~ /^README/ } << 'LICENSE'
13
13
  s.rdoc_options = %w[--line-numbers --inline-source --title Sinatra --main README.rdoc --encoding=UTF-8]
14
14
 
15
- s.add_dependency 'rack', '~> 1.3', '>= 1.3.6'
16
- s.add_dependency 'rack-protection', '~> 1.2'
15
+ s.add_dependency 'rack', '~> 1.4'
16
+ s.add_dependency 'rack-protection', '~> 1.3'
17
17
  s.add_dependency 'tilt', '~> 1.3', '>= 1.3.3'
18
18
  end
@@ -74,8 +74,9 @@ Tilt.mappings['md'].each do |t|
74
74
  t.new { "" }
75
75
  klass = Class.new(Test::Unit::TestCase) { define_method(:engine) { t }}
76
76
  klass.class_eval(&MarkdownTest)
77
- Object.const_set t.name[/[^:]+(?=Template$)/] << "Test", klass
78
- rescue LoadError
77
+ name = t.name[/[^:]+$/].sub(/Template$/, '') << "Test"
78
+ Object.const_set name, klass
79
+ rescue LoadError, NameError
79
80
  warn "#{$!}: skipping markdown tests with #{t}"
80
81
  end
81
82
  end
@@ -7,6 +7,11 @@ class ResponseTest < Test::Unit::TestCase
7
7
  @response = Sinatra::Response.new
8
8
  end
9
9
 
10
+ def assert_same_body(a, b)
11
+ enum = Enumerable.const_get(:Enumerator)
12
+ assert_equal enum.new(a).to_a, enum.new(b).to_a
13
+ end
14
+
10
15
  it "initializes with 200, text/html, and empty body" do
11
16
  assert_equal 200, @response.status
12
17
  assert_equal 'text/html', @response['Content-Type']
@@ -37,7 +42,7 @@ class ResponseTest < Test::Unit::TestCase
37
42
  @response.body = ['Hello', 'World!', '✈']
38
43
  status, headers, body = @response.finish
39
44
  assert_equal '14', headers['Content-Length']
40
- assert_equal @response.body, body
45
+ assert_same_body @response.body, body
41
46
  end
42
47
 
43
48
  it 'does not call #to_ary or #inject on the body' do
@@ -51,11 +56,11 @@ class ResponseTest < Test::Unit::TestCase
51
56
 
52
57
  it 'does not nest a Sinatra::Response' do
53
58
  @response.body = Sinatra::Response.new ["foo"]
54
- assert_equal @response.body, ["foo"]
59
+ assert_same_body @response.body, ["foo"]
55
60
  end
56
61
 
57
62
  it 'does not nest a Rack::Response' do
58
63
  @response.body = Rack::Response.new ["foo"]
59
- assert_equal @response.body, ["foo"]
64
+ assert_same_body @response.body, ["foo"]
60
65
  end
61
66
  end
@@ -335,6 +335,17 @@ class RoutingTest < Test::Unit::TestCase
335
335
  assert not_found?
336
336
  end
337
337
 
338
+ it "converts plus sign into space as the value of a named param" do
339
+ mock_app {
340
+ get '/:test' do
341
+ params["test"]
342
+ end
343
+ }
344
+ get '/bob+ross'
345
+ assert ok?
346
+ assert_equal 'bob ross', body
347
+ end
348
+
338
349
  it "literally matches parens in paths" do
339
350
  route_def '/test(bar)/'
340
351
 
@@ -537,6 +548,17 @@ class RoutingTest < Test::Unit::TestCase
537
548
  assert_equal 'HelloWorldHowAreYou', body
538
549
  end
539
550
 
551
+ it 'sets response.status with halt' do
552
+ status_was = nil
553
+ mock_app do
554
+ after { status_was = status }
555
+ get('/') { halt 500, 'error' }
556
+ end
557
+ get '/'
558
+ assert_status 500
559
+ assert_equal 500, status_was
560
+ end
561
+
540
562
  it "transitions to the next matching route on pass" do
541
563
  mock_app {
542
564
  get '/:foo' do
metadata CHANGED
@@ -1,15 +1,10 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: sinatra
3
- version: !ruby/object:Gem::Version
4
- hash: 29
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.3.4
5
5
  prerelease:
6
- segments:
7
- - 1
8
- - 3
9
- - 3
10
- version: 1.3.3
11
6
  platform: ruby
12
- authors:
7
+ authors:
13
8
  - Blake Mizerany
14
9
  - Ryan Tomayko
15
10
  - Simon Rozet
@@ -17,78 +12,68 @@ authors:
17
12
  autorequire:
18
13
  bindir: bin
19
14
  cert_chain: []
20
-
21
- date: 2012-08-19 00:00:00 +02:00
22
- default_executable:
23
- dependencies:
24
- - !ruby/object:Gem::Dependency
25
- version_requirements: &id001 !ruby/object:Gem::Requirement
15
+ date: 2013-01-26 00:00:00.000000000 Z
16
+ dependencies:
17
+ - !ruby/object:Gem::Dependency
18
+ name: rack
19
+ requirement: !ruby/object:Gem::Requirement
26
20
  none: false
27
- requirements:
21
+ requirements:
28
22
  - - ~>
29
- - !ruby/object:Gem::Version
30
- hash: 9
31
- segments:
32
- - 1
33
- - 3
34
- version: "1.3"
35
- - - ">="
36
- - !ruby/object:Gem::Version
37
- hash: 23
38
- segments:
39
- - 1
40
- - 3
41
- - 6
42
- version: 1.3.6
43
- requirement: *id001
44
- prerelease: false
45
- name: rack
23
+ - !ruby/object:Gem::Version
24
+ version: '1.4'
46
25
  type: :runtime
47
- - !ruby/object:Gem::Dependency
48
- version_requirements: &id002 !ruby/object:Gem::Requirement
26
+ prerelease: false
27
+ version_requirements: !ruby/object:Gem::Requirement
49
28
  none: false
50
- requirements:
29
+ requirements:
51
30
  - - ~>
52
- - !ruby/object:Gem::Version
53
- hash: 11
54
- segments:
55
- - 1
56
- - 2
57
- version: "1.2"
58
- requirement: *id002
59
- prerelease: false
31
+ - !ruby/object:Gem::Version
32
+ version: '1.4'
33
+ - !ruby/object:Gem::Dependency
60
34
  name: rack-protection
61
- type: :runtime
62
- - !ruby/object:Gem::Dependency
63
- version_requirements: &id003 !ruby/object:Gem::Requirement
35
+ requirement: !ruby/object:Gem::Requirement
64
36
  none: false
65
- requirements:
37
+ requirements:
66
38
  - - ~>
67
- - !ruby/object:Gem::Version
68
- hash: 9
69
- segments:
70
- - 1
71
- - 3
72
- version: "1.3"
73
- - - ">="
74
- - !ruby/object:Gem::Version
75
- hash: 29
76
- segments:
77
- - 1
78
- - 3
79
- - 3
80
- version: 1.3.3
81
- requirement: *id003
39
+ - !ruby/object:Gem::Version
40
+ version: '1.3'
41
+ type: :runtime
82
42
  prerelease: false
43
+ version_requirements: !ruby/object:Gem::Requirement
44
+ none: false
45
+ requirements:
46
+ - - ~>
47
+ - !ruby/object:Gem::Version
48
+ version: '1.3'
49
+ - !ruby/object:Gem::Dependency
83
50
  name: tilt
51
+ requirement: !ruby/object:Gem::Requirement
52
+ none: false
53
+ requirements:
54
+ - - ~>
55
+ - !ruby/object:Gem::Version
56
+ version: '1.3'
57
+ - - ! '>='
58
+ - !ruby/object:Gem::Version
59
+ version: 1.3.3
84
60
  type: :runtime
85
- description: Sinatra is a DSL for quickly creating web applications in Ruby with minimal effort.
61
+ prerelease: false
62
+ version_requirements: !ruby/object:Gem::Requirement
63
+ none: false
64
+ requirements:
65
+ - - ~>
66
+ - !ruby/object:Gem::Version
67
+ version: '1.3'
68
+ - - ! '>='
69
+ - !ruby/object:Gem::Version
70
+ version: 1.3.3
71
+ description: Sinatra is a DSL for quickly creating web applications in Ruby with minimal
72
+ effort.
86
73
  email: sinatrarb@googlegroups.com
87
74
  executables: []
88
-
89
75
  extensions: []
90
-
91
- extra_rdoc_files:
76
+ extra_rdoc_files:
92
77
  - README.de.rdoc
93
78
  - README.es.rdoc
94
79
  - README.fr.rdoc
@@ -101,7 +86,7 @@ extra_rdoc_files:
101
86
  - README.ru.rdoc
102
87
  - README.zh.rdoc
103
88
  - LICENSE
104
- files:
89
+ files:
105
90
  - .yardopts
106
91
  - AUTHORS
107
92
  - CHANGES
@@ -213,12 +198,10 @@ files:
213
198
  - test/views/layout2.test
214
199
  - test/views/nested.str
215
200
  - test/views/utf8.erb
216
- has_rdoc: true
217
201
  homepage: http://www.sinatrarb.com/
218
202
  licenses: []
219
-
220
203
  post_install_message:
221
- rdoc_options:
204
+ rdoc_options:
222
205
  - --line-numbers
223
206
  - --inline-source
224
207
  - --title
@@ -226,34 +209,33 @@ rdoc_options:
226
209
  - --main
227
210
  - README.rdoc
228
211
  - --encoding=UTF-8
229
- require_paths:
212
+ require_paths:
230
213
  - lib
231
- required_ruby_version: !ruby/object:Gem::Requirement
214
+ required_ruby_version: !ruby/object:Gem::Requirement
232
215
  none: false
233
- requirements:
234
- - - ">="
235
- - !ruby/object:Gem::Version
236
- hash: 3
237
- segments:
216
+ requirements:
217
+ - - ! '>='
218
+ - !ruby/object:Gem::Version
219
+ version: '0'
220
+ segments:
238
221
  - 0
239
- version: "0"
240
- required_rubygems_version: !ruby/object:Gem::Requirement
222
+ hash: -145507804200122103
223
+ required_rubygems_version: !ruby/object:Gem::Requirement
241
224
  none: false
242
- requirements:
243
- - - ">="
244
- - !ruby/object:Gem::Version
245
- hash: 3
246
- segments:
225
+ requirements:
226
+ - - ! '>='
227
+ - !ruby/object:Gem::Version
228
+ version: '0'
229
+ segments:
247
230
  - 0
248
- version: "0"
231
+ hash: -145507804200122103
249
232
  requirements: []
250
-
251
233
  rubyforge_project:
252
- rubygems_version: 1.6.2
234
+ rubygems_version: 1.8.23
253
235
  signing_key:
254
236
  specification_version: 3
255
237
  summary: Classy web-development dressed in a DSL
256
- test_files:
238
+ test_files:
257
239
  - test/base_test.rb
258
240
  - test/builder_test.rb
259
241
  - test/coffee_test.rb