Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
D
dropzonejs
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Custom Issue Tracker
Custom Issue Tracker
Labels
Merge Requests
1
Merge Requests
1
Requirements
Requirements
List
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Analytics
Analytics
Code Review
Insights
Issue
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
project
dropzonejs
Commits
a7477cd2
Commit
a7477cd2
authored
Mar 31, 2020
by
jungle
Committed by
chr.fritsch
Mar 31, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue
#2846920
by jungle, azcomi, alaa abbad: Make filename transliteration optional
parent
365cc0e6
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
57 additions
and
8 deletions
+57
-8
config/install/dropzonejs.settings.yml
config/install/dropzonejs.settings.yml
+1
-0
config/schema/dropzonejs.schema.yml
config/schema/dropzonejs.schema.yml
+3
-0
dropzonejs.install
dropzonejs.install
+11
-0
src/UploadHandler.php
src/UploadHandler.php
+10
-8
tests/src/Kernel/DropzoneJsUploadControllerTest.php
tests/src/Kernel/DropzoneJsUploadControllerTest.php
+32
-0
No files found.
config/install/dropzonejs.settings.yml
View file @
a7477cd2
tmp_upload_scheme
:
temporary
filename_transliteration
:
true
config/schema/dropzonejs.schema.yml
View file @
a7477cd2
...
...
@@ -5,3 +5,6 @@ dropzonejs.settings:
tmp_upload_scheme
:
type
:
string
label
:
'
Upload
scheme'
filename_transliteration
:
type
:
boolean
label
:
'
Transliterate
names
of
uploaded
files'
dropzonejs.install
View file @
a7477cd2
...
...
@@ -51,3 +51,14 @@ function dropzonejs_update_8001() {
$config
->
set
(
'tmp_upload_scheme'
,
'temporary'
);
$config
->
save
(
TRUE
);
}
/**
* Set default value for transliterate file name.
*/
function
dropzonejs_update_8002
()
{
$config_factory
=
\
Drupal
::
configFactory
();
$config
=
$config_factory
->
getEditable
(
'dropzonejs.settings'
);
$config
->
clear
(
'filename_transliteration'
);
$config
->
set
(
'filename_transliteration'
,
TRUE
);
$config
->
save
(
TRUE
);
}
src/UploadHandler.php
View file @
a7477cd2
...
...
@@ -44,11 +44,11 @@ class UploadHandler implements UploadHandlerInterface {
protected
$languageManager
;
/**
* The s
cheme (stream wrapper) used to store uploaded file
s.
* The s
ettings of dropzonej
s.
*
* @var
strin
g
* @var
\Drupal\Core\Config\ImmutableConfi
g
*/
protected
$
tmpUploadScheme
;
protected
$
dropzoneSettings
;
/**
* Constructs dropzone upload controller route controller.
...
...
@@ -66,7 +66,7 @@ class UploadHandler implements UploadHandlerInterface {
$this
->
request
=
$request_stack
->
getCurrentRequest
();
$this
->
transliteration
=
$transliteration
;
$this
->
languageManager
=
$language_manager
;
$this
->
tmpUploadScheme
=
$config_factory
->
get
(
'dropzonejs.settings'
)
->
get
(
'tmp_upload_scheme
'
);
$this
->
dropzoneSettings
=
$config_factory
->
get
(
'dropzonejs.settings
'
);
}
/**
...
...
@@ -81,6 +81,10 @@ class UploadHandler implements UploadHandlerInterface {
throw
new
UploadException
(
UploadException
::
FILENAME_ERROR
);
}
if
(
!
$this
->
dropzoneSettings
->
get
(
'filename_transliteration'
))
{
return
$original_name
.
'.txt'
;
}
// @todo The following filename sanitization steps replicate the behaviour
// of the 2492171-28 patch for https://www.drupal.org/node/2492171.
// Try to reuse that code instead, once that issue is committed.
...
...
@@ -100,9 +104,7 @@ class UploadHandler implements UploadHandlerInterface {
// For security reasons append the txt extension. It will be removed in
// Drupal\dropzonejs\Element::valueCallback when we will know the valid
// extension and we will be able to properly sanitize the filename.
$processed_filename
=
$filename
.
'.txt'
;
return
$processed_filename
;
return
$filename
.
'.txt'
;
}
/**
...
...
@@ -136,7 +138,7 @@ class UploadHandler implements UploadHandlerInterface {
}
// Open temp file.
$tmp
=
$this
->
tmpUploadScheme
.
'://'
.
$this
->
getFilename
(
$file
);
$tmp
=
$this
->
dropzoneSettings
->
get
(
'tmp_upload_scheme'
)
.
'://'
.
$this
->
getFilename
(
$file
);
if
(
!
(
$out
=
fopen
(
$tmp
,
$this
->
request
->
request
->
get
(
'chunk'
,
0
)
?
'ab'
:
'wb'
)))
{
throw
new
UploadException
(
UploadException
::
OUTPUT_ERROR
);
}
...
...
tests/src/Kernel/DropzoneJsUploadControllerTest.php
View file @
a7477cd2
...
...
@@ -98,4 +98,36 @@ class DropzoneJsUploadControllerTest extends KernelTestBase {
$this
->
assertEquals
(
file_get_contents
(
$result_file
),
$this
->
testfileData
);
}
/**
* Tests that dropzoneJs ignores filename transliteration.
*/
public
function
testIgnoreTransliteration
()
{
$this
->
container
->
get
(
'router.builder'
)
->
rebuild
();
$language
=
ConfigurableLanguage
::
createFromLangcode
(
'zh-hans'
);
$language
->
save
();
$this
->
config
(
'system.site'
)
->
set
(
'default_langcode'
,
$language
->
getId
())
->
save
();
$this
->
config
(
'dropzonejs.settings'
)
->
set
(
'filename_transliteration'
,
FALSE
)
->
save
();
// The filename should be expected as it is.
$chinese_with_emoji_fileanme_without_extension
=
'中文😁'
;
$uploaded_file
=
new
UploadedFile
(
$this
->
tmpFile
,
"
{
$this
->
testfilePrefix
}
${chinese_with_emoji_fileanme_without_extension}.jpg"
);
$file_bag
=
new
FileBag
();
$file_bag
->
set
(
'file'
,
$uploaded_file
);
$request
=
new
Request
();
$request
->
files
=
$file_bag
;
$upload_handler
=
$this
->
container
->
get
(
'dropzonejs.upload_handler'
);
$controller
=
new
UploadController
(
$upload_handler
,
$request
);
$controller_result
=
$controller
->
handleUploads
();
$this
->
assertInstanceOf
(
JsonResponse
::
class
,
$controller_result
);
$result
=
json_decode
(
$controller_result
->
getContent
());
$result_file
=
$this
->
filesDir
.
'/'
.
$result
->
result
;
$this
->
assertStringEndsWith
(
$chinese_with_emoji_fileanme_without_extension
.
'.jpg.txt'
,
$result_file
);
$this
->
assertFileExists
(
$result_file
);
$this
->
assertStringEqualsFile
(
$result_file
,
$this
->
testfileData
);
}
}
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