Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow file uris to include ? or # in filename #5043

Merged
merged 1 commit into from
Jan 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion app/services/file_locator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,9 @@ def location
when 's3'
S3File.new(uri).object.presigned_url(:get)
when 'file'
Addressable::URI.unencode(uri.path)
# In case file name includes ? or # use full uri omitting components before path
# instead of using only path which would miss query or fragment components
Addressable::URI.unencode(uri.omit(:scheme, :user, :password, :host, :port))
else
@uri.to_s
end
Expand Down
8 changes: 8 additions & 0 deletions spec/services/file_locator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,14 @@
expect(locator.attachment).to eq file
end
end

context "filename with reserved characters" do
let(:path) { "/path/to/file?#.mp4" }

it "should return the correct location" do
expect(locator.location).to eq path
end
end
end

describe "s3 file" do
Expand Down