diff --git a/config/routes.rb b/config/routes.rb
index 00b429f09fd..014d96b0780 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -384,11 +384,11 @@ Discourse::Application.routes.draw do
post "uploads" => "uploads#create"
# used to download original images
- get "uploads/:site/:sha" => "uploads#show", constraints: { site: /\w+/, sha: /[a-f0-9]{40}/ }
+ get "uploads/:site/:sha.:extension" => "uploads#show", constraints: { site: /\w+/, sha: /\h{40}/, extension: /[a-z0-9\.]+/i }
# used to download attachments
- get "uploads/:site/original/:tree:sha" => "uploads#show", constraints: { site: /\w+/, tree: /(\w+\/)+/i, sha: /[a-f0-9]{40}/ }
+ get "uploads/:site/original/:tree:sha.:extension" => "uploads#show", constraints: { site: /\w+/, tree: /([a-z0-9]+\/)+/i, sha: /\h{40}/, extension: /[a-z0-9\.]+/i }
# used to download attachments (old route)
- get "uploads/:site/:id/:sha" => "uploads#show", constraints: { site: /\w+/, id: /\d+/, sha: /[a-f0-9]{16}/ }
+ get "uploads/:site/:id/:sha" => "uploads#show", constraints: { site: /\w+/, id: /\d+/, sha: /\h{16}/ }
get "posts" => "posts#latest", id: "latest_posts"
get "private-posts" => "posts#latest", id: "private_posts"
diff --git a/lib/onebox/engine/discourse_local_onebox.rb b/lib/onebox/engine/discourse_local_onebox.rb
index 34bc2789619..44b60030390 100644
--- a/lib/onebox/engine/discourse_local_onebox.rb
+++ b/lib/onebox/engine/discourse_local_onebox.rb
@@ -34,9 +34,9 @@ module Onebox
def upload_html(path)
case File.extname(path)
- when /^\.(mov|mp4|webm|ogv)$/
+ when /^\.(mov|mp4|webm|ogv)$/i
""
- when /^\.(mp3|ogg|wav)$/
+ when /^\.(mp3|ogg|wav|m4a)$/i
""
end
end
diff --git a/spec/components/onebox/engine/discourse_local_onebox_spec.rb b/spec/components/onebox/engine/discourse_local_onebox_spec.rb
index c3b015befc8..3a6d0862ce6 100644
--- a/spec/components/onebox/engine/discourse_local_onebox_spec.rb
+++ b/spec/components/onebox/engine/discourse_local_onebox_spec.rb
@@ -66,20 +66,23 @@ describe Onebox::Engine::DiscourseLocalOnebox do
context "for a link to an internal audio or video file" do
+ let(:sha) { Digest::SHA1.hexdigest("discourse") }
+ let(:path) { "/uploads/default/original/3X/5/c/#{sha}" }
+
it "returns nil if file type is not audio or video" do
- url = "#{Discourse.base_url}/uploads/default/original/3X/5/c/24asdf42.pdf"
+ url = "#{Discourse.base_url}#{path}.pdf"
FakeWeb.register_uri(:get, url, body: "")
expect(Onebox.preview(url).to_s).to eq("")
end
it "returns some onebox goodness for audio file" do
- url = "#{Discourse.base_url}/uploads/default/original/3X/5/c/24asdf42.mp3"
+ url = "#{Discourse.base_url}#{path}.MP3"
html = Onebox.preview(url).to_s
expect(html).to eq("")
end
it "returns some onebox goodness for video file" do
- url = "#{Discourse.base_url}/uploads/default/original/3X/5/c/24asdf42.mp4"
+ url = "#{Discourse.base_url}#{path}.mov"
html = Onebox.preview(url).to_s
expect(html).to eq("")
end