addressable 2.5.0 → 2.5.1
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.
Potentially problematic release.
This version of addressable might be problematic. Click here for more details.
- checksums.yaml +4 -4
 - data/CHANGELOG.md +4 -0
 - data/README.md +2 -3
 - data/lib/addressable/template.rb +23 -9
 - data/lib/addressable/version.rb +1 -1
 - data/spec/addressable/template_spec.rb +33 -1
 - data/spec/addressable/uri_spec.rb +0 -8
 - metadata +2 -2
 
    
        checksums.yaml
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            ---
         
     | 
| 
       2 
2 
     | 
    
         
             
            SHA1:
         
     | 
| 
       3 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       4 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 3 
     | 
    
         
            +
              metadata.gz: 5bb436e09e69b39c2e10c2c3fe82c46519594528
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: 4aa7bdf211117af5bff34ab09b21e5104df60732
         
     | 
| 
       5 
5 
     | 
    
         
             
            SHA512:
         
     | 
| 
       6 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       7 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: 5b8404eb6f4d960d9d0973a45b2ef493d34f0ea2737b1c54fe3b1cc5035d74ba63f34ff155016fb4ff20111a5d605a19594c9a82a68085c2933dac9de3298c20
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: 0c1b0b8aaf248ddfd6d7196e16d00101f9570ef2efad31a4c7649cc813b48ab07b8050b8b3aa1b0fe3c0709c69652b5317dbcc9ba51d94c72eb55fd6b533e8db
         
     | 
    
        data/CHANGELOG.md
    CHANGED
    
    
    
        data/README.md
    CHANGED
    
    | 
         @@ -8,11 +8,10 @@ 
     | 
|
| 
       8 
8 
     | 
    
         
             
            </dl>
         
     | 
| 
       9 
9 
     | 
    
         | 
| 
       10 
10 
     | 
    
         
             
            [][gem]
         
     | 
| 
       11 
     | 
    
         
            -
            [][travis]
         
     | 
| 
      
 12 
     | 
    
         
            +
            [][gemnasium]
         
     | 
| 
       13 
13 
     | 
    
         
             
            [][coveralls]
         
     | 
| 
       14 
14 
     | 
    
         
             
            [][inch]
         
     | 
| 
       15 
     | 
    
         
            -
            [](https://www.gittip.com/sporkmonger/ "Support Open Source Development w/ Gittip")
         
     | 
| 
       16 
15 
     | 
    
         | 
| 
       17 
16 
     | 
    
         
             
            [gem]: https://rubygems.org/gems/addressable
         
     | 
| 
       18 
17 
     | 
    
         
             
            [travis]: http://travis-ci.org/sporkmonger/addressable
         
     | 
    
        data/lib/addressable/template.rb
    CHANGED
    
    | 
         @@ -488,6 +488,8 @@ module Addressable 
     | 
|
| 
       488 
488 
     | 
    
         
             
                # @param [Hash] mapping The mapping that corresponds to the pattern.
         
     | 
| 
       489 
489 
     | 
    
         
             
                # @param [#validate, #transform] processor
         
     | 
| 
       490 
490 
     | 
    
         
             
                #   An optional processor object may be supplied.
         
     | 
| 
      
 491 
     | 
    
         
            +
                # @param [Boolean] normalize_values
         
     | 
| 
      
 492 
     | 
    
         
            +
                #   Optional flag to enable/disable unicode normalization. Default: true
         
     | 
| 
       491 
493 
     | 
    
         
             
                #
         
     | 
| 
       492 
494 
     | 
    
         
             
                # The object should respond to either the <tt>validate</tt> or
         
     | 
| 
       493 
495 
     | 
    
         
             
                # <tt>transform</tt> messages or both. Both the <tt>validate</tt> and
         
     | 
| 
         @@ -518,11 +520,11 @@ module Addressable 
     | 
|
| 
       518 
520 
     | 
    
         
             
                #     "http://example.com/{?one,two,three}/"
         
     | 
| 
       519 
521 
     | 
    
         
             
                #   ).partial_expand({"one" => "1", "three" => 3}).pattern
         
     | 
| 
       520 
522 
     | 
    
         
             
                #   #=> "http://example.com/?one=1{&two}&three=3"
         
     | 
| 
       521 
     | 
    
         
            -
                def partial_expand(mapping, processor=nil)
         
     | 
| 
      
 523 
     | 
    
         
            +
                def partial_expand(mapping, processor=nil, normalize_values=true)
         
     | 
| 
       522 
524 
     | 
    
         
             
                  result = self.pattern.dup
         
     | 
| 
       523 
525 
     | 
    
         
             
                  mapping = normalize_keys(mapping)
         
     | 
| 
       524 
526 
     | 
    
         
             
                  result.gsub!( EXPRESSION ) do |capture|
         
     | 
| 
       525 
     | 
    
         
            -
                    transform_partial_capture(mapping, capture, processor)
         
     | 
| 
      
 527 
     | 
    
         
            +
                    transform_partial_capture(mapping, capture, processor, normalize_values)
         
     | 
| 
       526 
528 
     | 
    
         
             
                  end
         
     | 
| 
       527 
529 
     | 
    
         
             
                  return Addressable::Template.new(result)
         
     | 
| 
       528 
530 
     | 
    
         
             
                end
         
     | 
| 
         @@ -533,6 +535,8 @@ module Addressable 
     | 
|
| 
       533 
535 
     | 
    
         
             
                # @param [Hash] mapping The mapping that corresponds to the pattern.
         
     | 
| 
       534 
536 
     | 
    
         
             
                # @param [#validate, #transform] processor
         
     | 
| 
       535 
537 
     | 
    
         
             
                #   An optional processor object may be supplied.
         
     | 
| 
      
 538 
     | 
    
         
            +
                # @param [Boolean] normalize_values
         
     | 
| 
      
 539 
     | 
    
         
            +
                #   Optional flag to enable/disable unicode normalization. Default: true
         
     | 
| 
       536 
540 
     | 
    
         
             
                #
         
     | 
| 
       537 
541 
     | 
    
         
             
                # The object should respond to either the <tt>validate</tt> or
         
     | 
| 
       538 
542 
     | 
    
         
             
                # <tt>transform</tt> messages or both. Both the <tt>validate</tt> and
         
     | 
| 
         @@ -583,11 +587,11 @@ module Addressable 
     | 
|
| 
       583 
587 
     | 
    
         
             
                #     ExampleProcessor
         
     | 
| 
       584 
588 
     | 
    
         
             
                #   ).to_str
         
     | 
| 
       585 
589 
     | 
    
         
             
                #   #=> Addressable::Template::InvalidTemplateValueError
         
     | 
| 
       586 
     | 
    
         
            -
                def expand(mapping, processor=nil)
         
     | 
| 
      
 590 
     | 
    
         
            +
                def expand(mapping, processor=nil, normalize_values=true)
         
     | 
| 
       587 
591 
     | 
    
         
             
                  result = self.pattern.dup
         
     | 
| 
       588 
592 
     | 
    
         
             
                  mapping = normalize_keys(mapping)
         
     | 
| 
       589 
593 
     | 
    
         
             
                  result.gsub!( EXPRESSION ) do |capture|
         
     | 
| 
       590 
     | 
    
         
            -
                    transform_capture(mapping, capture, processor)
         
     | 
| 
      
 594 
     | 
    
         
            +
                    transform_capture(mapping, capture, processor, normalize_values)
         
     | 
| 
       591 
595 
     | 
    
         
             
                  end
         
     | 
| 
       592 
596 
     | 
    
         
             
                  return Addressable::URI.parse(result)
         
     | 
| 
       593 
597 
     | 
    
         
             
                end
         
     | 
| 
         @@ -704,6 +708,8 @@ module Addressable 
     | 
|
| 
       704 
708 
     | 
    
         
             
                #   The expression to expand
         
     | 
| 
       705 
709 
     | 
    
         
             
                # @param [#validate, #transform] processor
         
     | 
| 
       706 
710 
     | 
    
         
             
                #   An optional processor object may be supplied.
         
     | 
| 
      
 711 
     | 
    
         
            +
                # @param [Boolean] normalize_values
         
     | 
| 
      
 712 
     | 
    
         
            +
                #   Optional flag to enable/disable unicode normalization. Default: true
         
     | 
| 
       707 
713 
     | 
    
         
             
                #
         
     | 
| 
       708 
714 
     | 
    
         
             
                # The object should respond to either the <tt>validate</tt> or
         
     | 
| 
       709 
715 
     | 
    
         
             
                # <tt>transform</tt> messages or both. Both the <tt>validate</tt> and
         
     | 
| 
         @@ -718,7 +724,8 @@ module Addressable 
     | 
|
| 
       718 
724 
     | 
    
         
             
                # after sending the value to the transform method.
         
     | 
| 
       719 
725 
     | 
    
         
             
                #
         
     | 
| 
       720 
726 
     | 
    
         
             
                # @return [String] The expanded expression
         
     | 
| 
       721 
     | 
    
         
            -
                def transform_partial_capture(mapping, capture, processor = nil 
     | 
| 
      
 727 
     | 
    
         
            +
                def transform_partial_capture(mapping, capture, processor = nil,
         
     | 
| 
      
 728 
     | 
    
         
            +
                                              normalize_values = true)
         
     | 
| 
       722 
729 
     | 
    
         
             
                  _, operator, varlist = *capture.match(EXPRESSION)
         
     | 
| 
       723 
730 
     | 
    
         | 
| 
       724 
731 
     | 
    
         
             
                  vars = varlist.split(',')
         
     | 
| 
         @@ -740,7 +747,8 @@ module Addressable 
     | 
|
| 
       740 
747 
     | 
    
         
             
                      _, name, _ =  *varspec.match(VARSPEC)
         
     | 
| 
       741 
748 
     | 
    
         | 
| 
       742 
749 
     | 
    
         
             
                      acc << if mapping.key? name
         
     | 
| 
       743 
     | 
    
         
            -
                               transform_capture(mapping, "{#{op}#{varspec}}", 
     | 
| 
      
 750 
     | 
    
         
            +
                               transform_capture(mapping, "{#{op}#{varspec}}",
         
     | 
| 
      
 751 
     | 
    
         
            +
                                                 processor, normalize_values)
         
     | 
| 
       744 
752 
     | 
    
         
             
                             else
         
     | 
| 
       745 
753 
     | 
    
         
             
                               "{#{op}#{varspec}}"
         
     | 
| 
       746 
754 
     | 
    
         
             
                             end
         
     | 
| 
         @@ -780,6 +788,9 @@ module Addressable 
     | 
|
| 
       780 
788 
     | 
    
         
             
                #   The expression to replace
         
     | 
| 
       781 
789 
     | 
    
         
             
                # @param [#validate, #transform] processor
         
     | 
| 
       782 
790 
     | 
    
         
             
                #   An optional processor object may be supplied.
         
     | 
| 
      
 791 
     | 
    
         
            +
                # @param [Boolean] normalize_values
         
     | 
| 
      
 792 
     | 
    
         
            +
                #   Optional flag to enable/disable unicode normalization. Default: true
         
     | 
| 
      
 793 
     | 
    
         
            +
                #
         
     | 
| 
       783 
794 
     | 
    
         
             
                #
         
     | 
| 
       784 
795 
     | 
    
         
             
                # The object should respond to either the <tt>validate</tt> or
         
     | 
| 
       785 
796 
     | 
    
         
             
                # <tt>transform</tt> messages or both. Both the <tt>validate</tt> and
         
     | 
| 
         @@ -794,7 +805,8 @@ module Addressable 
     | 
|
| 
       794 
805 
     | 
    
         
             
                # after sending the value to the transform method.
         
     | 
| 
       795 
806 
     | 
    
         
             
                #
         
     | 
| 
       796 
807 
     | 
    
         
             
                # @return [String] The expanded expression
         
     | 
| 
       797 
     | 
    
         
            -
                def transform_capture(mapping, capture, processor=nil 
     | 
| 
      
 808 
     | 
    
         
            +
                def transform_capture(mapping, capture, processor=nil,
         
     | 
| 
      
 809 
     | 
    
         
            +
                                      normalize_values=true)
         
     | 
| 
       798 
810 
     | 
    
         
             
                  _, operator, varlist = *capture.match(EXPRESSION)
         
     | 
| 
       799 
811 
     | 
    
         
             
                  return_value = varlist.split(',').inject([]) do |acc, varspec|
         
     | 
| 
       800 
812 
     | 
    
         
             
                    _, name, modifier = *varspec.match(VARSPEC)
         
     | 
| 
         @@ -814,7 +826,7 @@ module Addressable 
     | 
|
| 
       814 
826 
     | 
    
         
             
                          "Can't convert #{value.class} into String or Array."
         
     | 
| 
       815 
827 
     | 
    
         
             
                      end
         
     | 
| 
       816 
828 
     | 
    
         | 
| 
       817 
     | 
    
         
            -
                      value = normalize_value(value)
         
     | 
| 
      
 829 
     | 
    
         
            +
                      value = normalize_value(value) if normalize_values
         
     | 
| 
       818 
830 
     | 
    
         | 
| 
       819 
831 
     | 
    
         
             
                      if processor == nil || !processor.respond_to?(:transform)
         
     | 
| 
       820 
832 
     | 
    
         
             
                        # Handle percent escaping
         
     | 
| 
         @@ -877,7 +889,9 @@ module Addressable 
     | 
|
| 
       877 
889 
     | 
    
         
             
                        end
         
     | 
| 
       878 
890 
     | 
    
         
             
                        if processor.respond_to?(:transform)
         
     | 
| 
       879 
891 
     | 
    
         
             
                          transformed_value = processor.transform(name, value)
         
     | 
| 
       880 
     | 
    
         
            -
                           
     | 
| 
      
 892 
     | 
    
         
            +
                          if normalize_values
         
     | 
| 
      
 893 
     | 
    
         
            +
                            transformed_value = normalize_value(transformed_value)
         
     | 
| 
      
 894 
     | 
    
         
            +
                          end
         
     | 
| 
       881 
895 
     | 
    
         
             
                        end
         
     | 
| 
       882 
896 
     | 
    
         
             
                      end
         
     | 
| 
       883 
897 
     | 
    
         
             
                      acc << [name, transformed_value]
         
     | 
    
        data/lib/addressable/version.rb
    CHANGED
    
    
| 
         @@ -91,7 +91,7 @@ describe "Type conversion" do 
     | 
|
| 
       91 
91 
     | 
    
         
             
                '{hello}' => '1234',
         
     | 
| 
       92 
92 
     | 
    
         
             
                '{nothing}' => '',
         
     | 
| 
       93 
93 
     | 
    
         
             
                '{sym}' => 'symbolic',
         
     | 
| 
       94 
     | 
    
         
            -
                '{decimal}' => '0.1E1'
         
     | 
| 
      
 94 
     | 
    
         
            +
                '{decimal}' => RUBY_VERSION < '2.4.0' ? '0.1E1' : '0.1e1'
         
     | 
| 
       95 
95 
     | 
    
         
             
              }
         
     | 
| 
       96 
96 
     | 
    
         
             
            end
         
     | 
| 
       97 
97 
     | 
    
         | 
| 
         @@ -969,6 +969,24 @@ describe Addressable::Template do 
     | 
|
| 
       969 
969 
     | 
    
         
             
                    )
         
     | 
| 
       970 
970 
     | 
    
         
             
                  end
         
     | 
| 
       971 
971 
     | 
    
         
             
                end
         
     | 
| 
      
 972 
     | 
    
         
            +
                context "partial expand with unicode values" do
         
     | 
| 
      
 973 
     | 
    
         
            +
                  subject do
         
     | 
| 
      
 974 
     | 
    
         
            +
                    Addressable::Template.new("http://example.com/{resource}/{query}/")
         
     | 
| 
      
 975 
     | 
    
         
            +
                  end
         
     | 
| 
      
 976 
     | 
    
         
            +
                  it "normalizes unicode by default" do
         
     | 
| 
      
 977 
     | 
    
         
            +
                    template = subject.partial_expand("query" => "Cafe\u0301")
         
     | 
| 
      
 978 
     | 
    
         
            +
                    expect(template.pattern).to eq(
         
     | 
| 
      
 979 
     | 
    
         
            +
                      "http://example.com/{resource}/Caf%C3%A9/"
         
     | 
| 
      
 980 
     | 
    
         
            +
                    )
         
     | 
| 
      
 981 
     | 
    
         
            +
                  end
         
     | 
| 
      
 982 
     | 
    
         
            +
             
     | 
| 
      
 983 
     | 
    
         
            +
                  it "does not normalize unicode when byte semantics requested" do
         
     | 
| 
      
 984 
     | 
    
         
            +
                    template = subject.partial_expand({"query" => "Cafe\u0301"}, nil, false)
         
     | 
| 
      
 985 
     | 
    
         
            +
                    expect(template.pattern).to eq(
         
     | 
| 
      
 986 
     | 
    
         
            +
                      "http://example.com/{resource}/Cafe%CC%81/"
         
     | 
| 
      
 987 
     | 
    
         
            +
                    )
         
     | 
| 
      
 988 
     | 
    
         
            +
                  end
         
     | 
| 
      
 989 
     | 
    
         
            +
                end
         
     | 
| 
       972 
990 
     | 
    
         
             
              end
         
     | 
| 
       973 
991 
     | 
    
         
             
              describe "Partial expand with strings" do
         
     | 
| 
       974 
992 
     | 
    
         
             
                context "partial_expand with two simple values" do
         
     | 
| 
         @@ -1013,6 +1031,20 @@ describe Addressable::Template do 
     | 
|
| 
       1013 
1031 
     | 
    
         
             
                end
         
     | 
| 
       1014 
1032 
     | 
    
         
             
              end
         
     | 
| 
       1015 
1033 
     | 
    
         
             
              describe "Expand" do
         
     | 
| 
      
 1034 
     | 
    
         
            +
                context "expand with unicode values" do
         
     | 
| 
      
 1035 
     | 
    
         
            +
                  subject do
         
     | 
| 
      
 1036 
     | 
    
         
            +
                    Addressable::Template.new("http://example.com/search/{query}/")
         
     | 
| 
      
 1037 
     | 
    
         
            +
                  end
         
     | 
| 
      
 1038 
     | 
    
         
            +
                  it "normalizes unicode by default" do
         
     | 
| 
      
 1039 
     | 
    
         
            +
                    uri = subject.expand("query" => "Cafe\u0301").to_str
         
     | 
| 
      
 1040 
     | 
    
         
            +
                    expect(uri).to eq("http://example.com/search/Caf%C3%A9/")
         
     | 
| 
      
 1041 
     | 
    
         
            +
                  end
         
     | 
| 
      
 1042 
     | 
    
         
            +
             
     | 
| 
      
 1043 
     | 
    
         
            +
                  it "does not normalize unicode when byte semantics requested" do
         
     | 
| 
      
 1044 
     | 
    
         
            +
                    uri = subject.expand({ "query" => "Cafe\u0301" }, nil, false).to_str
         
     | 
| 
      
 1045 
     | 
    
         
            +
                    expect(uri).to eq("http://example.com/search/Cafe%CC%81/")
         
     | 
| 
      
 1046 
     | 
    
         
            +
                  end
         
     | 
| 
      
 1047 
     | 
    
         
            +
                end
         
     | 
| 
       1016 
1048 
     | 
    
         
             
                context "expand with a processor" do
         
     | 
| 
       1017 
1049 
     | 
    
         
             
                  subject {
         
     | 
| 
       1018 
1050 
     | 
    
         
             
                    Addressable::Template.new("http://example.com/search/{query}/")
         
     | 
| 
         @@ -125,14 +125,6 @@ describe Addressable::URI, "when created with a non-string authority" do 
     | 
|
| 
       125 
125 
     | 
    
         
             
              end
         
     | 
| 
       126 
126 
     | 
    
         
             
            end
         
     | 
| 
       127 
127 
     | 
    
         | 
| 
       128 
     | 
    
         
            -
            describe Addressable::URI, "when created with a non-string authority" do
         
     | 
| 
       129 
     | 
    
         
            -
              it "should raise an error" do
         
     | 
| 
       130 
     | 
    
         
            -
                expect(lambda do
         
     | 
| 
       131 
     | 
    
         
            -
                  Addressable::URI.new(:authority => :bogus)
         
     | 
| 
       132 
     | 
    
         
            -
                end).to raise_error(TypeError)
         
     | 
| 
       133 
     | 
    
         
            -
              end
         
     | 
| 
       134 
     | 
    
         
            -
            end
         
     | 
| 
       135 
     | 
    
         
            -
             
     | 
| 
       136 
128 
     | 
    
         
             
            describe Addressable::URI, "when created with a non-string path" do
         
     | 
| 
       137 
129 
     | 
    
         
             
              it "should raise an error" do
         
     | 
| 
       138 
130 
     | 
    
         
             
                expect(lambda do
         
     | 
    
        metadata
    CHANGED
    
    | 
         @@ -1,14 +1,14 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            --- !ruby/object:Gem::Specification
         
     | 
| 
       2 
2 
     | 
    
         
             
            name: addressable
         
     | 
| 
       3 
3 
     | 
    
         
             
            version: !ruby/object:Gem::Version
         
     | 
| 
       4 
     | 
    
         
            -
              version: 2.5. 
     | 
| 
      
 4 
     | 
    
         
            +
              version: 2.5.1
         
     | 
| 
       5 
5 
     | 
    
         
             
            platform: ruby
         
     | 
| 
       6 
6 
     | 
    
         
             
            authors:
         
     | 
| 
       7 
7 
     | 
    
         
             
            - Bob Aman
         
     | 
| 
       8 
8 
     | 
    
         
             
            autorequire: 
         
     | 
| 
       9 
9 
     | 
    
         
             
            bindir: bin
         
     | 
| 
       10 
10 
     | 
    
         
             
            cert_chain: []
         
     | 
| 
       11 
     | 
    
         
            -
            date:  
     | 
| 
      
 11 
     | 
    
         
            +
            date: 2017-03-29 00:00:00.000000000 Z
         
     | 
| 
       12 
12 
     | 
    
         
             
            dependencies:
         
     | 
| 
       13 
13 
     | 
    
         
             
            - !ruby/object:Gem::Dependency
         
     | 
| 
       14 
14 
     | 
    
         
             
              name: public_suffix
         
     |