http_router 0.3.15 → 0.3.16

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/.gitignore CHANGED
@@ -3,3 +3,4 @@ pkg
3
3
  .bundle
4
4
  rdoc
5
5
  Gemfile.lock
6
+ .rvmrc
@@ -134,6 +134,11 @@ class HttpRouter
134
134
  current_nodes
135
135
  end
136
136
 
137
+ def escape_val(val)
138
+ val.is_a?(Array) ? val.each{|v| HttpRouter.uri_unescape!(v)} : HttpRouter.uri_unescape!(val)
139
+ val
140
+ end
141
+
137
142
  def find_on_parts(request, parts, params)
138
143
  if parts and !parts.empty?
139
144
  if potential = potential_match(request, parts, params)
@@ -147,7 +152,7 @@ class HttpRouter
147
152
  if tester.respond_to?(:matches?) and match = tester.matches?(parts)
148
153
  dupped_parts = parts.dup
149
154
  dupped_params = params.dup
150
- dupped_params.push((val = tester.consume(match, dupped_parts) and val.is_a?(Array)) ? val.map{|v| HttpRouter.uri_unescape(v)} : HttpRouter.uri_unescape(val))
155
+ dupped_params << escape_val(tester.consume(match, dupped_parts))
151
156
  parts.replace(dupped_parts) if response = node.find_on_parts(request, dupped_parts, dupped_params)
152
157
  elsif tester.respond_to?(:match) and match = tester.match(parts.whole_path) and match.begin(0) == 0
153
158
  dupped_parts = router.split(parts.whole_path[match[0].size, parts.whole_path.size])
@@ -171,7 +176,7 @@ class HttpRouter
171
176
  end
172
177
  end
173
178
  if @catchall
174
- params.push((val = @catchall.variable.consume(nil, parts) and val.is_a?(Array)) ? val.map{|v| HttpRouter.uri_unescape(v)} : HttpRouter.uri_unescape(val))
179
+ params << escape_val(@catchall.variable.consume(nil, parts))
175
180
  return @catchall.find_on_parts(request, parts, params)
176
181
  end
177
182
  end
@@ -336,6 +336,10 @@ class HttpRouter
336
336
  end
337
337
  end
338
338
 
339
+ def significant_variable_names
340
+ @significant_variable_names ||= @path.scan(/(^|[^\\])[:\*]([a-zA-Z0-9_]+)/).map{|p| p.last.to_sym}
341
+ end
342
+
339
343
  def generate_interstitial_parts(part)
340
344
  part_segments = part.scan(/:[a-zA-Z_0-9]+|[^:]+/)
341
345
  if part_segments.size > 1
@@ -366,13 +370,5 @@ class HttpRouter
366
370
  raise AlreadyCompiledException if compiled?
367
371
  end
368
372
 
369
- def significant_variable_names
370
- unless @significant_variable_names
371
- @significant_variable_names = @paths.map { |p| p.variable_names }
372
- @significant_variable_names.flatten!
373
- @significant_variable_names.uniq!
374
- end
375
- @significant_variable_names
376
- end
377
373
  end
378
374
  end
@@ -1,4 +1,4 @@
1
1
  # encoding: utf-8
2
2
  class HttpRouter #:nodoc
3
- VERSION = '0.3.15'
3
+ VERSION = '0.3.16'
4
4
  end
data/lib/http_router.rb CHANGED
@@ -259,8 +259,8 @@ class HttpRouter
259
259
  s.to_s.gsub!(/([^:\/?\[\]\-_~\.!\$&'\(\)\*\+,;=@a-zA-Z0-9]+)/n) { "%#{$1.unpack('H2'*$1.size).join('%').upcase}" }
260
260
  end
261
261
 
262
- def self.uri_unescape(s)
263
- s.to_s.gsub(/((?:%[0-9a-fA-F]{2})+)/n){ [$1.delete('%')].pack('H*') }
262
+ def self.uri_unescape!(s)
263
+ s.to_s.gsub!(/((?:%[0-9a-fA-F]{2})+)/n){ [$1.delete('%')].pack('H*') }
264
264
  end
265
265
 
266
266
  private
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: http_router
3
3
  version: !ruby/object:Gem::Version
4
- hash: 13
4
+ hash: 51
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 3
9
- - 15
10
- version: 0.3.15
9
+ - 16
10
+ version: 0.3.16
11
11
  platform: ruby
12
12
  authors:
13
13
  - Joshua Hull
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-09-03 00:00:00 -04:00
18
+ date: 2010-09-07 00:00:00 -04:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency