Commit 99d1f33d authored by Rémy Coutable's avatar Rémy Coutable

Merge branch...

Merge branch '20189-markdown-video-doesn-t-work-when-the-referenced-video-file-is-in-same-repo' into 'master'

Ensure relative paths for video are rewritten as we do for images

## What does this MR do?

This ensures that path to videos are rewritten as we do for images.

## Are there points in the code the reviewer needs to double check?

I've decided to add a new `Blob#video?` method for simplicity's sake but this should probably be added to `Gitlab::Git::Blob`.

## What are the relevant issue numbers?

Fixes #20189.

## Does this MR meet the acceptance criteria?

- [x] [CHANGELOG](https://gitlab.com/gitlab-org/gitlab-ce/blob/master/CHANGELOG) entry added
- Tests
  - [x] Added for this feature/bug
  - [ ] All builds are passing
- [x] Conform by the [style guides](https://gitlab.com/gitlab-org/gitlab-ce/blob/master/CONTRIBUTING.md#style-guides)
- [x] Branch has no merge conflicts with `master` (if you do - rebase it please)
- [x] [Squashed related commits together](https://git-scm.com/book/en/Git-Tools-Rewriting-History#Squashing-Commits)

See merge request !5474
Signed-off-by: default avatarRémy Coutable <remy@rymai.me>
parent 4af5d608
......@@ -8,6 +8,7 @@ v 8.10.2 (unreleased)
- Fix issue with autocomplete search not working with enter key. !5466
- Add iid to MR API response. !5468
- Disable MySQL foreign key checks before dropping all tables. !5472
- Ensure relative paths for video are rewritten as we do for images. !5474
- Don't show comment button in gutter of diffs on MR discussion tab
v 8.10.1
......
......@@ -31,6 +31,10 @@ class Blob < SimpleDelegator
text? && language && language.name == 'SVG'
end
def video?
UploaderHelper::VIDEO_EXT.include?(extname.downcase.delete('.'))
end
def to_partial_path
if lfs_pointer?
'download'
......
......@@ -295,8 +295,8 @@ class Commit
def uri_type(path)
entry = @raw.tree.path(path)
if entry[:type] == :blob
blob = Gitlab::Git::Blob.new(name: entry[:name])
blob.image? ? :raw : :blob
blob = ::Blob.decorate(Gitlab::Git::Blob.new(name: entry[:name]))
blob.image? || blob.video? ? :raw : :blob
else
entry[:type]
end
......
......@@ -20,7 +20,7 @@ module Banzai
process_link_attr el.attribute('href')
end
doc.search('img').each do |el|
doc.css('img, video').each do |el|
process_link_attr el.attribute('src')
end
......
......@@ -20,7 +20,7 @@ describe BranchesFinder do
result = branches_finder.execute
expect(result.first.name).to eq('expand-collapse-lines')
expect(result.first.name).to eq('video')
end
it 'sorts by last_updated' do
......
......@@ -19,6 +19,10 @@ describe Banzai::Filter::RelativeLinkFilter, lib: true do
%(<img src="#{path}" />)
end
def video(path)
%(<video src="#{path}"></video>)
end
def link(path)
%(<a href="#{path}">#{path}</a>)
end
......@@ -39,6 +43,12 @@ describe Banzai::Filter::RelativeLinkFilter, lib: true do
doc = filter(image('files/images/logo-black.png'))
expect(doc.at_css('img')['src']).to eq 'files/images/logo-black.png'
end
it 'does not modify any relative URL in video' do
doc = filter(video('files/videos/intro.mp4'), commit: project.commit('video'), ref: 'video')
expect(doc.at_css('video')['src']).to eq 'files/videos/intro.mp4'
end
end
shared_examples :relative_to_requested do
......@@ -113,11 +123,26 @@ describe Banzai::Filter::RelativeLinkFilter, lib: true do
end
it 'rebuilds relative URL for an image in the repo' do
doc = filter(image('files/images/logo-black.png'))
expect(doc.at_css('img')['src']).
to eq "/#{project_path}/raw/#{ref}/files/images/logo-black.png"
end
it 'rebuilds relative URL for link to an image in the repo' do
doc = filter(link('files/images/logo-black.png'))
expect(doc.at_css('a')['href']).
to eq "/#{project_path}/raw/#{ref}/files/images/logo-black.png"
end
it 'rebuilds relative URL for a video in the repo' do
doc = filter(video('files/videos/intro.mp4'), commit: project.commit('video'), ref: 'video')
expect(doc.at_css('video')['src']).
to eq "/#{project_path}/raw/video/files/videos/intro.mp4"
end
it 'does not modify relative URL with an anchor only' do
doc = filter(link('#section-1'))
expect(doc.at_css('a')['href']).to eq '#section-1'
......
......@@ -33,6 +33,22 @@ describe Blob do
end
end
describe '#video?' do
it 'is falsey with image extension' do
git_blob = Gitlab::Git::Blob.new(name: 'image.png')
expect(described_class.decorate(git_blob)).not_to be_video
end
UploaderHelper::VIDEO_EXT.each do |ext|
it "is truthy when extension is .#{ext}" do
git_blob = Gitlab::Git::Blob.new(name: "video.#{ext}")
expect(described_class.decorate(git_blob)).to be_video
end
end
end
describe '#to_partial_path' do
def stubbed_blob(overrides = {})
overrides.reverse_merge!(
......
......@@ -212,6 +212,7 @@ eos
it 'returns the URI type at the given path' do
expect(commit.uri_type('files/html')).to be(:tree)
expect(commit.uri_type('files/images/logo-black.png')).to be(:raw)
expect(project.commit('video').uri_type('files/videos/intro.mp4')).to be(:raw)
expect(commit.uri_type('files/js/application.js')).to be(:blob)
end
......
......@@ -20,7 +20,8 @@ module TestEnv
'gitattributes' => '5a62481',
'expand-collapse-diffs' => '4842455',
'expand-collapse-files' => '025db92',
'expand-collapse-lines' => '238e82d'
'expand-collapse-lines' => '238e82d',
'video' => '8879059'
}
# gitlab-test-fork is a fork of gitlab-fork, but we don't necessarily
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment