Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Léo-Paul Géneau
gitlab-ce
Commits
93943648
Commit
93943648
authored
Jul 25, 2016
by
Rémy Coutable
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Ensure relative paths for video are rewritten as we do for images
Signed-off-by:
Rémy Coutable
<
remy@rymai.me
>
parent
4bf20d67
Changes
9
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
53 additions
and
5 deletions
+53
-5
CHANGELOG
CHANGELOG
+1
-0
app/models/blob.rb
app/models/blob.rb
+4
-0
app/models/commit.rb
app/models/commit.rb
+2
-2
lib/banzai/filter/relative_link_filter.rb
lib/banzai/filter/relative_link_filter.rb
+1
-1
spec/finders/branches_finder_spec.rb
spec/finders/branches_finder_spec.rb
+1
-1
spec/lib/banzai/filter/relative_link_filter_spec.rb
spec/lib/banzai/filter/relative_link_filter_spec.rb
+25
-0
spec/models/blob_spec.rb
spec/models/blob_spec.rb
+16
-0
spec/models/commit_spec.rb
spec/models/commit_spec.rb
+1
-0
spec/support/test_env.rb
spec/support/test_env.rb
+2
-1
No files found.
CHANGELOG
View file @
93943648
...
@@ -18,6 +18,7 @@ v 8.10.2 (unreleased)
...
@@ -18,6 +18,7 @@ v 8.10.2 (unreleased)
- Fix backup restore. !5459
- Fix backup restore. !5459
- Disable MySQL foreign key checks before dropping all tables. !5472
- Disable MySQL foreign key checks before dropping all tables. !5472
- Use project ID in repository cache to prevent stale data from persisting across projects. !5460
- Use project ID in repository cache to prevent stale data from persisting across projects. !5460
- Ensure relative paths for video are rewritten as we do for images. !5474
v 8.10.1
v 8.10.1
- Refactor repository storages documentation. !5428
- Refactor repository storages documentation. !5428
...
...
app/models/blob.rb
View file @
93943648
...
@@ -31,6 +31,10 @@ class Blob < SimpleDelegator
...
@@ -31,6 +31,10 @@ class Blob < SimpleDelegator
text?
&&
language
&&
language
.
name
==
'SVG'
text?
&&
language
&&
language
.
name
==
'SVG'
end
end
def
video?
UploaderHelper
::
VIDEO_EXT
.
include?
(
extname
.
downcase
.
delete
(
'.'
))
end
def
to_partial_path
def
to_partial_path
if
lfs_pointer?
if
lfs_pointer?
'download'
'download'
...
...
app/models/commit.rb
View file @
93943648
...
@@ -295,8 +295,8 @@ class Commit
...
@@ -295,8 +295,8 @@ class Commit
def
uri_type
(
path
)
def
uri_type
(
path
)
entry
=
@raw
.
tree
.
path
(
path
)
entry
=
@raw
.
tree
.
path
(
path
)
if
entry
[
:type
]
==
:blob
if
entry
[
:type
]
==
:blob
blob
=
Gitlab
::
Git
::
Blob
.
new
(
name:
entry
[
:name
]
)
blob
=
::
Blob
.
decorate
(
Gitlab
::
Git
::
Blob
.
new
(
name:
entry
[
:name
])
)
blob
.
image?
?
:raw
:
:blob
blob
.
image?
||
blob
.
video?
?
:raw
:
:blob
else
else
entry
[
:type
]
entry
[
:type
]
end
end
...
...
lib/banzai/filter/relative_link_filter.rb
View file @
93943648
...
@@ -20,7 +20,7 @@ module Banzai
...
@@ -20,7 +20,7 @@ module Banzai
process_link_attr
el
.
attribute
(
'href'
)
process_link_attr
el
.
attribute
(
'href'
)
end
end
doc
.
search
(
'img
'
).
each
do
|
el
|
doc
.
css
(
'img, video
'
).
each
do
|
el
|
process_link_attr
el
.
attribute
(
'src'
)
process_link_attr
el
.
attribute
(
'src'
)
end
end
...
...
spec/finders/branches_finder_spec.rb
View file @
93943648
...
@@ -20,7 +20,7 @@ describe BranchesFinder do
...
@@ -20,7 +20,7 @@ describe BranchesFinder do
result
=
branches_finder
.
execute
result
=
branches_finder
.
execute
expect
(
result
.
first
.
name
).
to
eq
(
'
expand-collapse-lines
'
)
expect
(
result
.
first
.
name
).
to
eq
(
'
video
'
)
end
end
it
'sorts by last_updated'
do
it
'sorts by last_updated'
do
...
...
spec/lib/banzai/filter/relative_link_filter_spec.rb
View file @
93943648
...
@@ -17,6 +17,10 @@ describe Banzai::Filter::RelativeLinkFilter, lib: true do
...
@@ -17,6 +17,10 @@ describe Banzai::Filter::RelativeLinkFilter, lib: true do
%(<img src="#{path}" />)
%(<img src="#{path}" />)
end
end
def
video
(
path
)
%(<video src="#{path}"></video>)
end
def
link
(
path
)
def
link
(
path
)
%(<a href="#{path}">#{path}</a>)
%(<a href="#{path}">#{path}</a>)
end
end
...
@@ -37,6 +41,12 @@ describe Banzai::Filter::RelativeLinkFilter, lib: true do
...
@@ -37,6 +41,12 @@ describe Banzai::Filter::RelativeLinkFilter, lib: true do
doc
=
filter
(
image
(
'files/images/logo-black.png'
))
doc
=
filter
(
image
(
'files/images/logo-black.png'
))
expect
(
doc
.
at_css
(
'img'
)[
'src'
]).
to
eq
'files/images/logo-black.png'
expect
(
doc
.
at_css
(
'img'
)[
'src'
]).
to
eq
'files/images/logo-black.png'
end
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
end
shared_examples
:relative_to_requested
do
shared_examples
:relative_to_requested
do
...
@@ -111,11 +121,26 @@ describe Banzai::Filter::RelativeLinkFilter, lib: true do
...
@@ -111,11 +121,26 @@ describe Banzai::Filter::RelativeLinkFilter, lib: true do
end
end
it
'rebuilds relative URL for an image in the repo'
do
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'
))
doc
=
filter
(
link
(
'files/images/logo-black.png'
))
expect
(
doc
.
at_css
(
'a'
)[
'href'
]).
expect
(
doc
.
at_css
(
'a'
)[
'href'
]).
to
eq
"/
#{
project_path
}
/raw/
#{
ref
}
/files/images/logo-black.png"
to
eq
"/
#{
project_path
}
/raw/
#{
ref
}
/files/images/logo-black.png"
end
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
it
'does not modify relative URL with an anchor only'
do
doc
=
filter
(
link
(
'#section-1'
))
doc
=
filter
(
link
(
'#section-1'
))
expect
(
doc
.
at_css
(
'a'
)[
'href'
]).
to
eq
'#section-1'
expect
(
doc
.
at_css
(
'a'
)[
'href'
]).
to
eq
'#section-1'
...
...
spec/models/blob_spec.rb
View file @
93943648
...
@@ -33,6 +33,22 @@ describe Blob do
...
@@ -33,6 +33,22 @@ describe Blob do
end
end
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
describe
'#to_partial_path'
do
def
stubbed_blob
(
overrides
=
{})
def
stubbed_blob
(
overrides
=
{})
overrides
.
reverse_merge!
(
overrides
.
reverse_merge!
(
...
...
spec/models/commit_spec.rb
View file @
93943648
...
@@ -212,6 +212,7 @@ eos
...
@@ -212,6 +212,7 @@ eos
it
'returns the URI type at the given path'
do
it
'returns the URI type at the given path'
do
expect
(
commit
.
uri_type
(
'files/html'
)).
to
be
(
:tree
)
expect
(
commit
.
uri_type
(
'files/html'
)).
to
be
(
:tree
)
expect
(
commit
.
uri_type
(
'files/images/logo-black.png'
)).
to
be
(
:raw
)
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
)
expect
(
commit
.
uri_type
(
'files/js/application.js'
)).
to
be
(
:blob
)
end
end
...
...
spec/support/test_env.rb
View file @
93943648
...
@@ -20,7 +20,8 @@ module TestEnv
...
@@ -20,7 +20,8 @@ module TestEnv
'gitattributes'
=>
'5a62481'
,
'gitattributes'
=>
'5a62481'
,
'expand-collapse-diffs'
=>
'4842455'
,
'expand-collapse-diffs'
=>
'4842455'
,
'expand-collapse-files'
=>
'025db92'
,
'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
# gitlab-test-fork is a fork of gitlab-fork, but we don't necessarily
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment