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
1
Merge Requests
1
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
nexedi
gitlab-ce
Commits
3f4255cc
Commit
3f4255cc
authored
Apr 22, 2020
by
Phil Hughes
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixes upload links not copying as GFM correctly
Closes
https://gitlab.com/gitlab-org/gitlab/-/issues/214480
parent
1f05f317
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
32 additions
and
0 deletions
+32
-0
changelogs/unreleased/ph-214480-copyUploadLinks.yml
changelogs/unreleased/ph-214480-copyUploadLinks.yml
+5
-0
lib/banzai/filter/upload_link_filter.rb
lib/banzai/filter/upload_link_filter.rb
+4
-0
spec/features/markdown/copy_as_gfm_spec.rb
spec/features/markdown/copy_as_gfm_spec.rb
+6
-0
spec/lib/banzai/filter/upload_link_filter_spec.rb
spec/lib/banzai/filter/upload_link_filter_spec.rb
+17
-0
No files found.
changelogs/unreleased/ph-214480-copyUploadLinks.yml
0 → 100644
View file @
3f4255cc
---
title
:
Fixed copy as GFM not copying upload links
merge_request
:
29683
author
:
type
:
fixed
lib/banzai/filter/upload_link_filter.rb
View file @
3f4255cc
...
...
@@ -50,6 +50,10 @@ module Banzai
Addressable
::
URI
.
join
(
Gitlab
.
config
.
gitlab
.
base_url
,
path
).
to_s
end
if
html_attr
.
name
==
'href'
html_attr
.
parent
.
set_attribute
(
'data-link'
,
'true'
)
end
html_attr
.
parent
.
add_class
(
'gfm'
)
end
...
...
spec/features/markdown/copy_as_gfm_spec.rb
View file @
3f4255cc
...
...
@@ -172,6 +172,12 @@ describe 'Copy as GFM', :js do
'![Image](https://example.com/image.png)'
)
verify_media_with_partial_path
(
'[test.txt](/uploads/a123/image.txt)'
,
project_media_uri
(
@project
,
'/uploads/a123/image.txt'
)
)
verify_media_with_partial_path
(
'![Image](/uploads/a123/image.png)'
,
...
...
spec/lib/banzai/filter/upload_link_filter_spec.rb
View file @
3f4255cc
...
...
@@ -51,6 +51,7 @@ describe Banzai::Filter::UploadLinkFilter do
expect
(
doc
.
at_css
(
'a'
)[
'href'
]).
to
eq
(
absolute_path
)
expect
(
doc
.
at_css
(
'a'
).
classes
).
to
include
(
'gfm'
)
expect
(
doc
.
at_css
(
'a'
)[
'data-link'
]).
to
eq
(
'true'
)
end
end
...
...
@@ -59,11 +60,13 @@ describe Banzai::Filter::UploadLinkFilter do
expect
(
doc
.
at_css
(
'a'
)[
'href'
]).
to
eq
(
relative_path
)
expect
(
doc
.
at_css
(
'a'
).
classes
).
to
include
(
'gfm'
)
expect
(
doc
.
at_css
(
'a'
)[
'data-link'
]).
to
eq
(
'true'
)
doc
=
filter
(
nested
(
link
(
upload_path
)))
expect
(
doc
.
at_css
(
'a'
)[
'href'
]).
to
eq
(
relative_path
)
expect
(
doc
.
at_css
(
'a'
).
classes
).
to
include
(
'gfm'
)
expect
(
doc
.
at_css
(
'a'
)[
'data-link'
]).
to
eq
(
'true'
)
end
it
'rebuilds relative URL for an image'
do
...
...
@@ -71,11 +74,13 @@ describe Banzai::Filter::UploadLinkFilter do
expect
(
doc
.
at_css
(
'img'
)[
'src'
]).
to
eq
(
relative_path
)
expect
(
doc
.
at_css
(
'img'
).
classes
).
to
include
(
'gfm'
)
expect
(
doc
.
at_css
(
'img'
)[
'data-link'
]).
not_to
eq
(
'true'
)
doc
=
filter
(
nested
(
image
(
upload_path
)))
expect
(
doc
.
at_css
(
'img'
)[
'src'
]).
to
eq
(
relative_path
)
expect
(
doc
.
at_css
(
'img'
).
classes
).
to
include
(
'gfm'
)
expect
(
doc
.
at_css
(
'img'
)[
'data-link'
]).
not_to
eq
(
'true'
)
end
it
'does not modify absolute URL'
do
...
...
@@ -83,6 +88,7 @@ describe Banzai::Filter::UploadLinkFilter do
expect
(
doc
.
at_css
(
'a'
)[
'href'
]).
to
eq
'http://example.com'
expect
(
doc
.
at_css
(
'a'
).
classes
).
not_to
include
(
'gfm'
)
expect
(
doc
.
at_css
(
'a'
)[
'data-link'
]).
not_to
eq
(
'true'
)
end
it
'supports unescaped Unicode filenames'
do
...
...
@@ -91,6 +97,7 @@ describe Banzai::Filter::UploadLinkFilter do
expect
(
doc
.
at_css
(
'a'
)[
'href'
]).
to
eq
(
"/
#{
project
.
full_path
}
/uploads/%ED%95%9C%EA%B8%80.png"
)
expect
(
doc
.
at_css
(
'a'
).
classes
).
to
include
(
'gfm'
)
expect
(
doc
.
at_css
(
'a'
)[
'data-link'
]).
to
eq
(
'true'
)
end
it
'supports escaped Unicode filenames'
do
...
...
@@ -100,6 +107,7 @@ describe Banzai::Filter::UploadLinkFilter do
expect
(
doc
.
at_css
(
'img'
)[
'src'
]).
to
eq
(
"/
#{
project
.
full_path
}
/uploads/%ED%95%9C%EA%B8%80.png"
)
expect
(
doc
.
at_css
(
'img'
).
classes
).
to
include
(
'gfm'
)
expect
(
doc
.
at_css
(
'img'
)[
'data-link'
]).
not_to
eq
(
'true'
)
end
end
...
...
@@ -118,6 +126,7 @@ describe Banzai::Filter::UploadLinkFilter do
expect
(
doc
.
at_css
(
'a'
)[
'href'
]).
to
eq
(
absolute_path
)
expect
(
doc
.
at_css
(
'a'
).
classes
).
to
include
(
'gfm'
)
expect
(
doc
.
at_css
(
'a'
)[
'data-link'
]).
to
eq
(
'true'
)
end
end
...
...
@@ -126,6 +135,7 @@ describe Banzai::Filter::UploadLinkFilter do
expect
(
doc
.
at_css
(
'a'
)[
'href'
]).
to
eq
(
relative_path
)
expect
(
doc
.
at_css
(
'a'
).
classes
).
to
include
(
'gfm'
)
expect
(
doc
.
at_css
(
'a'
)[
'data-link'
]).
to
eq
(
'true'
)
end
it
'rewrites the link correctly for subgroup'
do
...
...
@@ -135,6 +145,7 @@ describe Banzai::Filter::UploadLinkFilter do
expect
(
doc
.
at_css
(
'a'
)[
'href'
]).
to
eq
(
relative_path
)
expect
(
doc
.
at_css
(
'a'
).
classes
).
to
include
(
'gfm'
)
expect
(
doc
.
at_css
(
'a'
)[
'data-link'
]).
to
eq
(
'true'
)
end
it
'does not modify absolute URL'
do
...
...
@@ -142,6 +153,7 @@ describe Banzai::Filter::UploadLinkFilter do
expect
(
doc
.
at_css
(
'a'
)[
'href'
]).
to
eq
'http://example.com'
expect
(
doc
.
at_css
(
'a'
).
classes
).
not_to
include
(
'gfm'
)
expect
(
doc
.
at_css
(
'a'
)[
'data-link'
]).
not_to
eq
(
'true'
)
end
end
...
...
@@ -159,6 +171,7 @@ describe Banzai::Filter::UploadLinkFilter do
expect
(
doc
.
at_css
(
'a'
)[
'href'
]).
to
eq
(
absolute_path
)
expect
(
doc
.
at_css
(
'a'
).
classes
).
to
include
(
'gfm'
)
expect
(
doc
.
at_css
(
'a'
)[
'data-link'
]).
to
eq
(
'true'
)
end
end
...
...
@@ -178,6 +191,7 @@ describe Banzai::Filter::UploadLinkFilter do
expect
(
doc
.
at_css
(
'a'
)[
'href'
]).
to
eq
(
absolute_path
)
expect
(
doc
.
at_css
(
'a'
).
classes
).
to
include
(
'gfm'
)
expect
(
doc
.
at_css
(
'a'
)[
'data-link'
]).
to
eq
(
'true'
)
end
end
...
...
@@ -186,6 +200,7 @@ describe Banzai::Filter::UploadLinkFilter do
expect
(
doc
.
at_css
(
'a'
)[
'href'
]).
to
eq
(
gitlab_root
+
relative_path
)
expect
(
doc
.
at_css
(
'a'
).
classes
).
to
include
(
'gfm'
)
expect
(
doc
.
at_css
(
'a'
)[
'data-link'
]).
to
eq
(
'true'
)
end
end
...
...
@@ -194,6 +209,7 @@ describe Banzai::Filter::UploadLinkFilter do
expect
(
doc
.
at_css
(
'a'
)[
'href'
]).
to
eq
(
relative_path
)
expect
(
doc
.
at_css
(
'a'
).
classes
).
to
include
(
'gfm'
)
expect
(
doc
.
at_css
(
'a'
)[
'data-link'
]).
to
eq
(
'true'
)
end
it
'does not modify absolute URL'
do
...
...
@@ -201,6 +217,7 @@ describe Banzai::Filter::UploadLinkFilter do
expect
(
doc
.
at_css
(
'a'
)[
'href'
]).
to
eq
'http://example.com'
expect
(
doc
.
at_css
(
'a'
).
classes
).
not_to
include
(
'gfm'
)
expect
(
doc
.
at_css
(
'a'
)[
'data-link'
]).
not_to
eq
(
'true'
)
end
end
...
...
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