Skip to content

Commit

Permalink
(PUP-6036) Escape path when validating content_uri
Browse files Browse the repository at this point in the history
The content_uri metadata is composed from the source scheme, host, and
port, and the path of the file on disk, relative to the per-environment
directory. Since the path can contain characters that must be
percent-encoded, e.g. 'foo%bar', we need to escape the path prior to
trying to parse the URI.
  • Loading branch information
joshcooper committed Mar 10, 2016
1 parent 9453f09 commit 3daa532
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/puppet/file_serving/metadata.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def source_permissions=(source_permissions)

def content_uri=(path)
begin
uri = URI.parse(path)
uri = URI.parse(URI.escape(path))
rescue URI::InvalidURIError => detail
raise(ArgumentError, "Could not understand URI #{path}: #{detail}")
end
Expand Down
8 changes: 7 additions & 1 deletion spec/unit/file_serving/metadata_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,13 @@

describe "when assigning a content_uri" do
it "should fail if uri is invalid" do
expect { metadata.content_uri = 'some foo' }.to raise_error ArgumentError, /Could not understand URI some foo: /
expect { metadata.content_uri = '://' }.to raise_error ArgumentError, /Could not understand URI :\/\//
end

it "should accept characters that require percent-encoding" do
uri = 'puppet:///modules/foo/files/ %:?#[]@!$&\'()*+,;='
metadata.content_uri = uri
expect(metadata.content_uri).to eq(uri)
end

it "should fail if uri is opaque" do
Expand Down

0 comments on commit 3daa532

Please sign in to comment.