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
Kazuhiko Shiozaki
gitlab-ce
Commits
4e22dcb6
Commit
4e22dcb6
authored
Jul 30, 2015
by
Robert Speicher
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add spec to RelativeLinkFilter for Unicode filenames
parent
6d6f807b
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
27 additions
and
2 deletions
+27
-2
lib/gitlab/markdown/relative_link_filter.rb
lib/gitlab/markdown/relative_link_filter.rb
+11
-2
spec/lib/gitlab/markdown/relative_link_filter_spec.rb
spec/lib/gitlab/markdown/relative_link_filter_spec.rb
+16
-0
No files found.
lib/gitlab/markdown/relative_link_filter.rb
View file @
4e22dcb6
...
@@ -99,15 +99,24 @@ module Gitlab
...
@@ -99,15 +99,24 @@ module Gitlab
# Returns a String
# Returns a String
def
path_type
(
path
)
def
path_type
(
path
)
unescaped_path
=
Addressable
::
URI
.
unescape
(
path
)
unescaped_path
=
Addressable
::
URI
.
unescape
(
path
)
if
repository
.
tree
(
current_sha
,
unescaped_path
).
entries
.
any?
if
tree?
(
unescaped_path
)
'tree'
'tree'
elsif
repository
.
blob_at
(
current_sha
,
unescaped_path
).
try
(
:image?
)
elsif
image?
(
unescaped_path
)
'raw'
'raw'
else
else
'blob'
'blob'
end
end
end
end
def
tree?
(
path
)
repository
.
tree
(
current_sha
,
path
).
entries
.
any?
end
def
image?
(
path
)
repository
.
blob_at
(
current_sha
,
path
).
try
(
:image?
)
end
def
current_sha
def
current_sha
context
[
:commit
].
try
(
:id
)
||
context
[
:commit
].
try
(
:id
)
||
ref
?
repository
.
commit
(
ref
).
try
(
:sha
)
:
repository
.
head_commit
.
sha
ref
?
repository
.
commit
(
ref
).
try
(
:sha
)
:
repository
.
head_commit
.
sha
...
...
spec/lib/gitlab/markdown/relative_link_filter_spec.rb
View file @
4e22dcb6
# encoding: UTF-8
require
'spec_helper'
require
'spec_helper'
module
Gitlab::Markdown
module
Gitlab::Markdown
...
@@ -101,6 +103,20 @@ module Gitlab::Markdown
...
@@ -101,6 +103,20 @@ module Gitlab::Markdown
expect
(
doc
.
at_css
(
'a'
)[
'href'
]).
to
eq
'http://example.com'
expect
(
doc
.
at_css
(
'a'
)[
'href'
]).
to
eq
'http://example.com'
end
end
it
'supports Unicode filenames'
do
path
=
'files/images/한글.png'
escaped
=
Addressable
::
URI
.
escape
(
path
)
# Stub these methods so the file doesn't actually need to be in the repo
allow_any_instance_of
(
described_class
).
to
receive
(
:file_exists?
).
and_return
(
true
)
allow_any_instance_of
(
described_class
).
to
receive
(
:image?
).
with
(
path
).
and_return
(
true
)
doc
=
filter
(
image
(
escaped
))
expect
(
doc
.
at_css
(
'img'
)[
'src'
]).
to
match
'/raw/'
end
context
'when requested path is a file in the repo'
do
context
'when requested path is a file in the repo'
do
let
(
:requested_path
)
{
'doc/api/README.md'
}
let
(
:requested_path
)
{
'doc/api/README.md'
}
include_examples
:relative_to_requested
include_examples
:relative_to_requested
...
...
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