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
f67211f9
Commit
f67211f9
authored
Sep 07, 2018
by
Francisco Javier López
Committed by
Douwe Maan
Sep 07, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Replace whitespaces in wiki page attachments file names
parent
7f2b287f
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
38 additions
and
3 deletions
+38
-3
app/services/wikis/create_attachment_service.rb
app/services/wikis/create_attachment_service.rb
+10
-2
changelogs/unreleased/fj-51194-fix-wiki-attachments-with-whitespaces.yml
...leased/fj-51194-fix-wiki-attachments-with-whitespaces.yml
+5
-0
spec/services/wikis/create_attachment_service_spec.rb
spec/services/wikis/create_attachment_service_spec.rb
+23
-1
No files found.
app/services/wikis/create_attachment_service.rb
View file @
f67211f9
...
...
@@ -11,7 +11,7 @@ module Wikis
def
initialize
(
*
args
)
super
@file_name
=
truncate
_file_name
(
params
[
:file_name
])
@file_name
=
clean
_file_name
(
params
[
:file_name
])
@file_path
=
File
.
join
(
ATTACHMENT_PATH
,
SecureRandom
.
hex
,
@file_name
)
if
@file_name
@commit_message
||=
"Upload attachment
#{
@file_name
}
"
@branch_name
||=
wiki
.
default_branch
...
...
@@ -23,8 +23,16 @@ module Wikis
private
def
truncate
_file_name
(
file_name
)
def
clean
_file_name
(
file_name
)
return
unless
file_name
.
present?
file_name
=
truncate_file_name
(
file_name
)
# CommonMark does not allow Urls with whitespaces, so we have to replace them
# Using the same regex Carrierwave use to replace invalid characters
file_name
.
gsub
(
CarrierWave
::
SanitizedFile
.
sanitize_regexp
,
'_'
)
end
def
truncate_file_name
(
file_name
)
return
file_name
if
file_name
.
length
<=
MAX_FILENAME_LENGTH
extension
=
File
.
extname
(
file_name
)
...
...
changelogs/unreleased/fj-51194-fix-wiki-attachments-with-whitespaces.yml
0 → 100644
View file @
f67211f9
---
title
:
Replace white spaces in wiki attachments file names
merge_request
:
21569
author
:
type
:
fixed
spec/services/wikis/create_attachment_service_spec.rb
View file @
f67211f9
...
...
@@ -88,8 +88,30 @@ describe Wikis::CreateAttachmentService do
end
end
describe
'
validations
'
do
describe
'
#parse_file_name
'
do
context
'when file_name'
do
context
'has white spaces'
do
let
(
:file_name
)
{
'file with spaces'
}
it
"replaces all of them with '_'"
do
result
=
service
.
execute
expect
(
result
[
:status
]).
to
eq
:success
expect
(
result
[
:result
][
:file_name
]).
to
eq
'file_with_spaces'
end
end
context
'has other invalid characters'
do
let
(
:file_name
)
{
"file
\t
with
\t
invalid chars"
}
it
"replaces all of them with '_'"
do
result
=
service
.
execute
expect
(
result
[
:status
]).
to
eq
:success
expect
(
result
[
:result
][
:file_name
]).
to
eq
'file_with_invalid_chars'
end
end
context
'is not present'
do
let
(
:file_name
)
{
nil
}
...
...
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