diff options
author | Jay Mundrawala <jdmundrawala@gmail.com> | 2015-05-05 07:15:10 -0700 |
---|---|---|
committer | Jay Mundrawala <jdmundrawala@gmail.com> | 2015-05-15 07:04:19 -0700 |
commit | 3b5beef887ad02f634b386713d406b77bb876d17 (patch) | |
tree | 1c3f19a25fd16bd15ac2b27ed161663b7913f5e8 | |
parent | 53ae86b9eb116d156bed369f99be02acea86cdad (diff) | |
download | chef-3b5beef887ad02f634b386713d406b77bb876d17.tar.gz |
Use custom uri matcher
URI.split matches C:/, which we do not want
-rw-r--r-- | lib/chef/mixin/uris.rb | 7 | ||||
-rw-r--r-- | spec/unit/mixin/uris_spec.rb | 45 |
2 files changed, 47 insertions, 5 deletions
diff --git a/lib/chef/mixin/uris.rb b/lib/chef/mixin/uris.rb index 40b95d082e..d0ce052ef6 100644 --- a/lib/chef/mixin/uris.rb +++ b/lib/chef/mixin/uris.rb @@ -22,11 +22,8 @@ class Chef module Mixin module Uris def uri_scheme?(source) - begin - !URI.split(source).first.nil? - rescue URI::InvalidURIError - return false - end + # From open-uri + !!(%r{\A[A-Za-z][A-Za-z0-9+\-\.]*://} =~ source) end end end diff --git a/spec/unit/mixin/uris_spec.rb b/spec/unit/mixin/uris_spec.rb new file mode 100644 index 0000000000..07e4f34508 --- /dev/null +++ b/spec/unit/mixin/uris_spec.rb @@ -0,0 +1,45 @@ +# +# Author:: Jay Mundrawala (<jdm@chef.io>) +# Copyright:: Copyright (c) 2015 Chef Software, Inc. +# License:: Apache License, Version 2.0 +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +require 'spec_helper' +require 'chef/mixin/uris' + +class Chef::UrisTest + include Chef::Mixin::Uris +end + +describe Chef::Mixin::Uris do + let (:uris) { Chef::UrisTest.new } + + it "matches 'scheme://foo.com'" do + expect(uris.uri_scheme?('scheme://foo.com')).to eq(true) + end + + it "does not match 'c:/foo.com'" do + expect(uris.uri_scheme?('c:/foo.com')).to eq(false) + end + + it "does not match '/usr/bin/foo.com'" do + expect(uris.uri_scheme?('/usr/bin/foo.com')).to eq(false) + end + + it "does not match 'c:/foo.com://bar.com'" do + expect(uris.uri_scheme?('c:/foo.com://bar.com')).to eq(false) + end + +end |