Skip to content
Snippets Groups Projects
Commit 15ff3c27 authored by Evan Battaglia's avatar Evan Battaglia Committed by SaltNPepa
Browse files

Allow tempfile_for_url to take a URL with no path

Ran into this locally when testing some new code where I use this

refs INTEROP-9084
flag=none

Test plan:
- specs

Change-Id: Idea84e7b4b1465bb942f833eb26299a3585f4aa3
Reviewed-on: https://gerrit.instructure.com/c/canvas-lms/+/370053


Reviewed-by: default avatarDavid Varga <d.varga@instructure.com>
QA-Review: David Varga <d.varga@instructure.com>
Tested-by: default avatarService Cloud Jenkins <svc.cloudjenkins@instructure.com>
Product-Review: Evan Battaglia <ebattaglia@instructure.com>
parent 9325d0fc
No related merge requests found
......@@ -323,9 +323,10 @@ module CanvasHttp
# returns a tempfile with a filename based on the uri (same extension, if
# there was an extension)
def self.tempfile_for_uri(uri)
basename = File.basename(uri.path)
basename = File.basename(uri.path || "")
basename, ext = basename.split(".", 2)
basename = basename.slice(0, 100)
basename = (basename || "").slice(0, 100)
tmpfile = if ext
Tempfile.new([basename, ext])
else
......
......@@ -298,8 +298,9 @@ describe "CanvasHttp" do
end
describe ".tempfile_for_url" do
let(:tempfile) { double("tempfile") }
before do
tempfile = double("tempfile")
allow(tempfile).to receive(:binmode)
allow(Tempfile).to receive(:new).and_return(tempfile)
end
......@@ -308,6 +309,11 @@ describe "CanvasHttp" do
expect(Tempfile).to receive(:new).with("1234567890" * 10)
CanvasHttp.tempfile_for_uri(URI.parse("1234567890" * 12))
end
it "doesn't crash when given a URI with no path" do
res = CanvasHttp.tempfile_for_uri(URI.parse("http://example.com"))
expect(res).to eq(tempfile)
end
end
describe ".connection_for_uri" do
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment