Esempio n. 1
0
 public function testValidateName()
 {
     $this->assertFalse(FileHelper::validateName(''));
     $this->assertTrue(FileHelper::validateName('01test-testdat'));
     $this->assertTrue(FileHelper::validateName('test/testdat'));
     $this->assertFalse(FileHelper::validateName('test\\testdat'));
     $this->assertTrue(FileHelper::validateName('01test-test.dat'));
     $this->assertFalse(FileHelper::validateName('*****@*****.**'));
     $this->assertFalse(FileHelper::validateName('test::test'));
     $this->assertFalse(FileHelper::validateName('@test'));
 }
Esempio n. 2
0
 /**
  * Sets the object file name.
  * @param string $fileName Specifies the file name.
  * @return \Cms\Classes\CmsObject Returns the object instance.
  */
 public function setFileName($fileName)
 {
     $fileName = trim($fileName);
     if (!strlen($fileName)) {
         throw new ValidationException(['fileName' => Lang::get('cms::lang.cms_object.file_name_required', ['allowed' => implode(', ', static::$allowedExtensions), 'invalid' => pathinfo($fileName, PATHINFO_EXTENSION)])]);
     }
     if (!FileHelper::validateExtension($fileName, static::$allowedExtensions)) {
         throw new ValidationException(['fileName' => Lang::get('cms::lang.cms_object.invalid_file_extension', ['allowed' => implode(', ', static::$allowedExtensions), 'invalid' => pathinfo($fileName, PATHINFO_EXTENSION)])]);
     }
     if (!FileHelper::validatePath($fileName, static::getMaxAllowedPathNesting())) {
         throw new ValidationException(['fileName' => Lang::get('cms::lang.cms_object.invalid_file', ['name' => $fileName])]);
     }
     if (!strlen(File::extension($fileName))) {
         $fileName .= '.htm';
     }
     $this->fileName = $fileName;
     return $this;
 }
Esempio n. 3
0
 /**
  * Validate the supplied filename, extension and path.
  * @param string $fileName
  */
 protected function validateFileName($fileName = null)
 {
     if ($fileName === null) {
         $fileName = $this->fileName;
     }
     $fileName = trim($fileName);
     if (!strlen($fileName)) {
         throw new ValidationException(['fileName' => Lang::get('cms::lang.cms_object.file_name_required', ['allowed' => implode(', ', $this->allowedExtensions), 'invalid' => pathinfo($fileName, PATHINFO_EXTENSION)])]);
     }
     if (!FileHelper::validateExtension($fileName, $this->allowedExtensions, false)) {
         throw new ValidationException(['fileName' => Lang::get('cms::lang.cms_object.invalid_file_extension', ['allowed' => implode(', ', $this->allowedExtensions), 'invalid' => pathinfo($fileName, PATHINFO_EXTENSION)])]);
     }
 }
Esempio n. 4
0
 /**
  * Checks the supplied file name for validity.
  * @param string  $fileName
  * @return string
  */
 protected function validateFileName($fileName)
 {
     if (!FileHelper::validatePath($fileName, $this->maxNesting)) {
         throw new ApplicationException(Lang::get('cms::lang.cms_object.invalid_file', ['name' => $fileName]));
     }
     if (!strlen(File::extension($fileName))) {
         $fileName .= '.' . $this->defaultExtension;
     }
     return $fileName;
 }