Skip to content

Commit

Permalink
Allow hyphens in media filenames (since we added '\w' for allowing pe…
Browse files Browse the repository at this point in the history
…riods in filenames).
  • Loading branch information
jkeck committed Apr 28, 2016
1 parent 427196d commit 80477a3
Show file tree
Hide file tree
Showing 3 changed files with 114 additions and 2 deletions.
4 changes: 2 additions & 2 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
get '/file/auth/:id/:file_name' => 'webauth#login_file', as: :auth_file
end

constraints file_name: %r{[^/][\w]+} do
constraints file_name: %r{[^/][\w-]+} do
get '/media/:id/:file_name' => 'media#download', as: :media
get '/media/auth/:id/:file_name' => 'webauth#login_media_download', as: :auth_media_download
end

# stream file_name must include format extension, eg .../oo000oo0000.mp4/stream
constraints file_name: %r{[^/][\w\.]+} do
constraints file_name: %r{[^/][\w\.-]+} do
get '/media/:id/:file_name/stream' => 'media#stream', as: :media_stream
get '/media/auth/:id/:file_name/stream' => 'webauth#login_media_stream', as: :auth_media_stream
end
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions spec/routing/media_routing_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@
expect(get: '/media/oo000oo0000/aa666aa1234.mp4').to route_to(
'media#download', id: 'oo000oo0000', file_name: 'aa666aa1234', format: 'mp4')
end

it 'download: filename with hyphen' do
expect(get: '/media/oo000oo0000/aa666aa1234-a.mp4').to route_to(
'media#download', id: 'oo000oo0000', file_name: 'aa666aa1234-a', format: 'mp4')
end

it 'stream: filename with format suffix' do
expect(get: '/media/oo000oo0000/aa666aa1234.mp4/stream.m3u8').to route_to(
'media#stream', id: 'oo000oo0000', file_name: 'aa666aa1234.mp4', format: 'm3u8')
Expand All @@ -14,6 +20,11 @@
'media#stream', id: 'oo000oo0000', file_name: 'aa666aa1234.mov', format: 'm3u8')
end

it 'stream: filename with hyphen' do
expect(get: '/media/oo000oo0000/aa666aa1234-a.mp4/stream.m3u8').to route_to(
'media#stream', id: 'oo000oo0000', file_name: 'aa666aa1234-a.mp4', format: 'm3u8')
end

describe 'authorization' do
it 'download routes to #login_media_download' do
expect(get: '/media/auth/id/filename.mp4').to route_to(
Expand Down

0 comments on commit 80477a3

Please sign in to comment.