Skip to content
Snippets Groups Projects
Commit ff957f7e authored by suhyeonh's avatar suhyeonh
Browse files

Merge remote-tracking branch 'origin' into feature/test-update

parents f7fe9f99 538fcba1
No related branches found
No related tags found
1 merge request!5update test case
...@@ -25,12 +25,12 @@ interface MinisiteInterface { ...@@ -25,12 +25,12 @@ interface MinisiteInterface {
/** /**
* Default allowed extensions. * Default allowed extensions.
*/ */
const ALLOWED_EXTENSIONS = 'html htm js css png jpg gif svg pdf doc docx ppt pptx xls xlsx tif xml txt woff woff2 ttf eot ico'; const ALLOWED_EXTENSIONS = 'html htm js css png jpg gif svg pdf docx ppt pptx xls xlsx tif xml txt woff woff2 ttf eot ico';
/** /**
* Extensions that can never be allowed. * Extensions that can never be allowed.
*/ */
const DENIED_EXTENSIONS = 'exe scr bmp'; const DENIED_EXTENSIONS = 'exe scr bmp php doc rtf';
/** /**
* Archive extensions supported by the current implementation. * Archive extensions supported by the current implementation.
......
...@@ -174,14 +174,19 @@ class MinisiteItem extends FileItem { ...@@ -174,14 +174,19 @@ class MinisiteItem extends FileItem {
/** /**
* Check that entered extensions are not in the denied extensions list. * Check that entered extensions are not in the denied extensions list.
*
* By default, this list is defined in MinisiteInterface.php but can
* be overriden by creating an environment variable file '.env' and creating
* an environment variable DENIED_EXTENSIONS. E.g:
*
* DENIED_EXTENSIONS="exe php bat"
*/ */
public static function validateNoDeniedExtensions($element, FormStateInterface $form_state) { public static function validateNoDeniedExtensions($element, FormStateInterface $form_state) {
if (!empty($element['#value'])) { if (!empty($element['#value'])) {
$extensions = preg_replace('/([, ]+\.?)/', ' ', trim(strtolower($element['#value']))); $extensions = preg_replace('/([, ]+\.?)/', ' ', trim(strtolower($element['#value'])));
$extensions = array_filter(explode(' ', $extensions)); $extensions = array_filter(explode(' ', $extensions));
$denied_extensions = getenv('DENIED_EXTENSIONS') ?: MinisiteInterface::DENIED_EXTENSIONS;
$denied_extensions = explode(' ', MinisiteInterface::DENIED_EXTENSIONS); $denied_extensions = explode(' ', $denied_extensions);
$invalid_extensions = array_intersect($extensions, $denied_extensions); $invalid_extensions = array_intersect($extensions, $denied_extensions);
if (count($invalid_extensions) > 0) { if (count($invalid_extensions) > 0) {
$form_state->setError($element, t('The list of allowed extensions is not valid, be sure to not include %ext extension(s).', ['%ext' => implode(', ', $invalid_extensions)])); $form_state->setError($element, t('The list of allowed extensions is not valid, be sure to not include %ext extension(s).', ['%ext' => implode(', ', $invalid_extensions)]));
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment