rewritten 0.16.4 → 0.16.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a254642e07ed0bb8b46f4c9ebe95a152ac94481e
4
- data.tar.gz: 52fe0a75b830039b7d2a0b78a05e13c4e902df53
3
+ metadata.gz: c1341c9fb6a042d2864f1cc01c903650661a55de
4
+ data.tar.gz: 24354a7bdc753c6038edd3871579d5e5c49b209f
5
5
  SHA512:
6
- metadata.gz: b7835a4629b4980b5276a0a55a3da1d8017ca7cb117b5619b0c52167413ad14a485e10bab38f737fdc4a6e6b2b5b042959f7ca3a21cfdf8d93b2ce59e0e90e53
7
- data.tar.gz: a40d86b684035a29ea2be929d94d071a522ac352a4d0a9dc148c6434d6b55dd75f9df87ebf2f3dfb13b190c52747e3ac5840d60349a3eff670a5eb0bd5542f28
6
+ metadata.gz: 2a2ae4fb9c6a89d26da98461eba2a7580506cc9180764754cc497b7138f4d4906f66c4f94df787bdbf1e9ad4aa21b4bd76f7da180b47009cdd46808169203228
7
+ data.tar.gz: 1699d501b7b6df4037f5576fd8794670ba3a73de135b6a787f48f9567fc71cba482a95f7d5ae1f9c215b90146a16c0c4d8bebf025e10bdec1917750a4b354ef7
@@ -1,3 +1,7 @@
1
+ == 0.16.4
2
+
3
+ * Fix trailing slash with query string redirect
4
+
1
5
  == 0.16.4
2
6
 
3
7
  * Fix trailing slash redirect
@@ -29,17 +29,19 @@ module Rack
29
29
  subdomain = env['SUBDOMAIN'] ? "#{env['SUBDOMAIN']}:" : ''
30
30
 
31
31
  path = "#{subdomain}#{req.path_info}"
32
- path.downcase! if downcase_before_lookup?
32
+ path.downcase! if downcase_before_lookup
33
33
 
34
34
  target_url = ::Rewritten.translate(path)
35
35
 
36
+ chomped_fullpath = req.fullpath.split('?').map { |s| s.chomp('/') }.join('?')
37
+
36
38
  if external_target?(target_url)
37
39
  r = Rack::Response.new
38
40
  r.redirect(target_url, 301)
39
41
  r.finish
40
- elsif ::Rewritten.includes?(req.fullpath) || ::Rewritten.includes?(path.chomp('/')) || backwards = (translate_backwards?(path) && ::Rewritten.exist_translation_for?(path))
42
+ elsif ::Rewritten.includes?(chomped_fullpath) || ::Rewritten.includes?(path.chomp('/')) || backwards = (translate_backwards?(path) && ::Rewritten.exist_translation_for?(path))
41
43
 
42
- to = ::Rewritten.includes?(req.fullpath)
44
+ to = ::Rewritten.includes?(chomped_fullpath)
43
45
  to ||= ::Rewritten.includes?(path.chomp('/')) || path
44
46
 
45
47
  current_path = ::Rewritten.get_current_translation(to)
@@ -54,18 +56,18 @@ module Rack
54
56
  new_path << '://'
55
57
  new_path << env['HTTP_HOST'].dup.sub(/^#{subdomain.chomp(':')}\./, '')
56
58
  new_path << current_path
57
- new_path << ::Rewritten.appendix(path) unless backwards
59
+ new_path << ::Rewritten.appendix(chomped_fullpath) unless backwards
58
60
  new_path << '?' << env['QUERY_STRING'] unless (env['QUERY_STRING'] || '').empty?
59
61
 
60
62
  r.redirect(new_path, 301)
61
63
  return r.finish
62
64
  end
63
65
 
64
- if (req.fullpath == current_path_with_query || current_path == req.path_info) || (::Rewritten.base_from(req.path_info) == current_path) || ::Rewritten.flag?(path, 'L')
66
+ if (chomped_fullpath == current_path_with_query || current_path == req.path_info) || (::Rewritten.base_from(req.path_info) == current_path) || ::Rewritten.flag?(path, 'L')
65
67
  # if this is the current path, rewrite path and parameters
66
68
  tpath, tparams = split_to_path_params(to)
67
69
  env['QUERY_STRING'] = Rack::Utils.build_nested_query(tparams.merge(req.params))
68
- req.path_info = tpath + ::Rewritten.appendix(req.fullpath)
70
+ req.path_info = tpath + ::Rewritten.appendix(chomped_fullpath)
69
71
  @app.call(req.env)
70
72
  else
71
73
  # if this is not the current path, redirect to current path
@@ -107,16 +109,7 @@ module Rack
107
109
 
108
110
  attr_writer :translate_backwards
109
111
  attr_accessor :translate_backwards_exceptions
110
-
111
- def downcase_before_lookup?
112
- @downcase_before_lookup
113
- end
114
-
115
- attr_writer :downcase_before_lookup
116
-
117
- def translate_partial?
118
- @translate_partial
119
- end
112
+ attr_accessor :downcase_before_lookup
120
113
 
121
114
  def translate_partial=(yes_or_no)
122
115
  $stderr.puts 'DEPRECATED. Please use Rewritten.translate_partial'
@@ -41,11 +41,7 @@ module Rewritten
41
41
  end
42
42
  end
43
43
 
44
- attr_writer :translate_partial
45
-
46
- def translate_partial?
47
- @translate_partial
48
- end
44
+ attr_accessor :translate_partial
49
45
 
50
46
  # Returns the current Redis connection. If none has been created, will
51
47
  # create a new one.
@@ -194,7 +190,7 @@ module Rewritten
194
190
  translation = Rewritten.z_range("to:#{uri.path}", -1) unless translation
195
191
 
196
192
  if translation.nil?
197
- if translate_partial? && path.count('/') > 1
193
+ if translate_partial && path.count('/') > 1
198
194
  parts = path.split('/')
199
195
  shorter_path = parts.slice(0, parts.size - 1).join('/')
200
196
  appendix = parts.last + (tail ? '/' + tail : '')
@@ -221,7 +217,7 @@ module Rewritten
221
217
  to = translate(conjugated)
222
218
  to = translate(conjugated.split('?')[0]) unless to
223
219
 
224
- if to.nil? && translate_partial? && conjugated.count('/') > 1
220
+ if to.nil? && translate_partial && conjugated.count('/') > 1
225
221
  parts = conjugated.split('/')
226
222
  shorter_path = parts.slice(0, parts.size - 1).join('/')
227
223
  infinitive(shorter_path)
@@ -238,7 +234,7 @@ module Rewritten
238
234
  some_from
239
235
  elsif translate(base_from)
240
236
  base_from
241
- elsif translate_partial? && base_from.count('/') > 1
237
+ elsif translate_partial && base_from.count('/') > 1
242
238
  parts = base_from.split('/')
243
239
  base_from(parts.slice(0, parts.size - 1).join('/'))
244
240
  end
@@ -287,7 +283,7 @@ module Rewritten
287
283
  result = Rewritten.redis.hget("from:#{path.chomp('/')}", :to)
288
284
  result = Rewritten.redis.hget("from:#{path.split('?')[0]}", :to) unless result
289
285
 
290
- if result.nil? && translate_partial? && path.count('/') > 1
286
+ if result.nil? && translate_partial && path.count('/') > 1
291
287
  parts = path.split('/')
292
288
  includes?(parts.slice(0, parts.size - 1).join('/'))
293
289
  else
@@ -1,3 +1,3 @@
1
1
  module Rewritten
2
- VERSION = '0.16.4'
2
+ VERSION = '0.16.5'
3
3
  end
@@ -141,13 +141,21 @@ describe Rack::Rewritten::Url do
141
141
  ret[1]['Location'].must_equal 'http://www.example.org/foo/baz'
142
142
  end
143
143
 
144
+ it 'must 301 redirect current paths with / before the query string to their chomped version' do
145
+ Rewritten.add_translation '/path/with/params?w=1', '/embed/2'
146
+ ret = @rack.call request_url('/path/with/params/', 'QUERY_STRING' => 'w=1')
147
+ @app.verify
148
+ ret[0].must_equal 301
149
+ ret[1]['Location'].must_equal 'http://www.example.org/path/with/params?w=1'
150
+ end
151
+
144
152
  it 'wont 301 redirect /' do
145
153
  @app.expect :call, [200, { 'Content-Type' => 'text/plain' }, ['']], [Hash]
146
154
  ret = @rack.call request_url('/')
147
155
  @app.verify
148
156
  end
149
157
 
150
- it 'must 301 redirect paths with / in the end to their current chomped version' do
158
+ it 'must 301 redirect non-current paths with / in the end to their current chomped version' do
151
159
  ret = @rack.call request_url('/foo/bar/')
152
160
  @app.verify
153
161
  ret[0].must_equal 301
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rewritten
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.16.4
4
+ version: 0.16.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kai Rubarth
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-03-16 00:00:00.000000000 Z
11
+ date: 2016-03-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: redis-namespace