addressable 2.0.1 → 2.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG CHANGED
@@ -1,3 +1,7 @@
1
+ === Addressable 2.0.2
2
+ * fixed issue with URI template expansion
3
+ * fixed issue with percent escaping characters 0-15
4
+
1
5
  === Addressable 2.0.1
2
6
  * fixed issue with query string assignment
3
7
  * fixed issue with improperly encoded components
@@ -281,7 +281,10 @@ module Addressable
281
281
  # <tt>false</tt> otherwise. An <tt>InvalidTemplateValueError</tt>
282
282
  # exception will be raised if the value is invalid. The
283
283
  # <tt>transform</tt> method should return the transformed variable
284
- # value as a <tt>String</tt>.
284
+ # value as a <tt>String</tt>. If a <tt>transform</tt> method is used,
285
+ # the value will not be percent encoded automatically. Unicode
286
+ # normalization will be performed both before and after sending the
287
+ # value to the transform method.
285
288
  #
286
289
  # @return [Addressable::URI] The expanded URI template.
287
290
  #
@@ -336,22 +339,27 @@ module Addressable
336
339
  raise TypeError,
337
340
  "Can't convert #{value.class} into String or Array."
338
341
  end
339
- transformed_value =
342
+
343
+ value =
340
344
  value.respond_to?(:to_ary) ? value.to_ary : value.to_str
345
+ # Handle unicode normalization
346
+ if value.kind_of?(Array)
347
+ value.map! { |val| Addressable::IDNA.unicode_normalize_kc(val) }
348
+ else
349
+ value = Addressable::IDNA.unicode_normalize_kc(value)
350
+ end
341
351
 
342
- # Handle percent escaping, and unicode normalization
343
- if transformed_value.kind_of?(Array)
344
- transformed_value.map! do |value|
345
- self.encode_component(
346
- Addressable::IDNA.unicode_normalize_kc(value),
347
- Addressable::URI::CharacterClasses::UNRESERVED
348
- )
352
+ if processor == nil || !processor.respond_to?(:transform)
353
+ # Handle percent escaping
354
+ if value.kind_of?(Array)
355
+ transformed_value = value.map do |val|
356
+ self.encode_component(
357
+ val, Addressable::URI::CharacterClasses::UNRESERVED)
358
+ end
359
+ else
360
+ transformed_value = self.encode_component(
361
+ value, Addressable::URI::CharacterClasses::UNRESERVED)
349
362
  end
350
- else
351
- transformed_value = self.encode_component(
352
- Addressable::IDNA.unicode_normalize_kc(transformed_value),
353
- Addressable::URI::CharacterClasses::UNRESERVED
354
- )
355
363
  end
356
364
 
357
365
  # Process, if we've got a processor
@@ -365,6 +373,14 @@ module Addressable
365
373
  end
366
374
  if processor.respond_to?(:transform)
367
375
  transformed_value = processor.transform(name, value)
376
+ if transformed_value.kind_of?(Array)
377
+ transformed_value.map! do |val|
378
+ Addressable::IDNA.unicode_normalize_kc(val)
379
+ end
380
+ else
381
+ transformed_value =
382
+ Addressable::IDNA.unicode_normalize_kc(transformed_value)
383
+ end
368
384
  end
369
385
  end
370
386
 
@@ -958,7 +974,7 @@ module Addressable
958
974
  character_class = /[^#{character_class}]/
959
975
  end
960
976
  return component.gsub(character_class) do |sequence|
961
- (sequence.unpack('C*').map { |c| "%#{c.to_s(16).upcase}" }).join("")
977
+ (sequence.unpack('C*').map { |c| "%" + ("%02x" % c).upcase }).join("")
962
978
  end
963
979
  end
964
980
 
@@ -27,7 +27,7 @@ if !defined?(Addressable::VERSION)
27
27
  module VERSION #:nodoc:
28
28
  MAJOR = 2
29
29
  MINOR = 0
30
- TINY = 1
30
+ TINY = 2
31
31
 
32
32
  STRING = [MAJOR, MINOR, TINY].join('.')
33
33
  end
@@ -69,6 +69,12 @@ class SlashlessProcessor
69
69
  end
70
70
  end
71
71
 
72
+ class NoOpProcessor
73
+ def self.transform(name, value)
74
+ value
75
+ end
76
+ end
77
+
72
78
  describe Addressable::URI, "when created with a non-numeric port number" do
73
79
  it "should raise an error" do
74
80
  (lambda do
@@ -3571,6 +3577,15 @@ describe Addressable::URI, "when given a mapping that contains an Array" do
3571
3577
  @mapping).to_s.should ==
3572
3578
  "http://example.com/search/an+example+search+query/"
3573
3579
  end
3580
+
3581
+ it "should result in 'http://example.com/search/an+example+search+query/'" +
3582
+ " when used to expand 'http://example.com/search/{-list|+|query}/'" +
3583
+ " with a NoOpProcessor" do
3584
+ Addressable::URI.expand_template(
3585
+ "http://example.com/search/{-list|+|query}/",
3586
+ @mapping, NoOpProcessor).to_s.should ==
3587
+ "http://example.com/search/an+example+search+query/"
3588
+ end
3574
3589
  end
3575
3590
 
3576
3591
  class SuperString
@@ -3617,6 +3632,18 @@ describe Addressable::URI, "when encoding a multibyte string" do
3617
3632
  end
3618
3633
  end
3619
3634
 
3635
+ describe Addressable::URI, "when encoding a string with ASCII chars 0-15" do
3636
+ it "should result in correct percent encoded sequence" do
3637
+ Addressable::URI.encode_component("one\ntwo").should == "one%0Atwo"
3638
+ end
3639
+
3640
+ it "should result in correct percent encoded sequence" do
3641
+ Addressable::URI.encode_component(
3642
+ "one\ntwo", /[^a-zA-Z0-9\:\/\?\#\[\]\@\!\$\&\'\(\)\*\+\,\;\=\-\.\_\~]/
3643
+ ).should == "one%0Atwo"
3644
+ end
3645
+ end
3646
+
3620
3647
  describe Addressable::URI, "when unencoding a multibyte string" do
3621
3648
  it "should result in correct percent encoded sequence" do
3622
3649
  Addressable::URI.unencode_component("g%C3%BCnther").should == "günther"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: addressable
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.1
4
+ version: 2.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bob Aman
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-12-02 00:00:00 -05:00
12
+ date: 2009-01-30 00:00:00 -05:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency