Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
ContentValidator.php
Go to the documentation of this file.
1 <?php
7 
10 
12 {
20  public function isValid(ContentInterface $fileContent)
21  {
22  $decodedContent = @base64_decode($fileContent->getFileData(), true);
23  if (empty($decodedContent)) {
24  throw new InputException(__('Provided content must be valid base64 encoded data.'));
25  }
26 
27  if (!$this->isFileNameValid($fileContent->getName())) {
28  throw new InputException(__('Provided file name contains forbidden characters.'));
29  }
30  return true;
31  }
32 
39  protected function isFileNameValid($fileName)
40  {
41  // Cannot contain \ / : * ? " < > |
42  if (!preg_match('/^[^\\/?*:";<>()|{}\\\\]+$/', $fileName)) {
43  return false;
44  }
45  return true;
46  }
47 }
__()
Definition: __.php:13
$fileName
Definition: translate.phtml:15