Fixes validation of requested partial names VS. partial names on file system

This commit is contained in:
Sam Georges 2014-07-06 12:42:08 +10:00
parent 7395dc520a
commit 7ecf361eb3
4 changed files with 5 additions and 3 deletions

View File

@ -308,7 +308,7 @@ class Controller extends Extendable
// @todo Do we need to validate backend partials?
// foreach ($partialList as $partial) {
// if (!CmsFileHelper::validateName($partial))
// if (!preg_match('/^(?:\w+\:{2}|@)?[a-z0-9\_\-\.\/]+$/i', $partial))
// throw new SystemException(Lang::get('cms::lang.partial.invalid_name', ['name'=>$partial]));
// }
}

View File

@ -332,7 +332,7 @@ class Controller extends BaseController
$partialList = explode('&', $partialList);
foreach ($partialList as $partial) {
if (!CmsFileHelper::validateName($partial))
if (!preg_match('/^(?:\w+\:{2}|@)?[a-z0-9\_\-\.\/]+$/i', $partial))
throw new CmsException(Lang::get('cms::lang.partial.invalid_name', ['name'=>$partial]));
}
}

View File

@ -17,7 +17,7 @@ class FileHelper
*/
public static function validateName($fileName)
{
return preg_match('/^([a-z0-9\-\.]+\:{2})?[a-z0-9\_\-\.\/]+$/i', $fileName) ? true : false;
return preg_match('/^[a-z0-9\_\-\.\/]+$/i', $fileName) ? true : false;
}
/**

View File

@ -12,6 +12,8 @@ class FileHelperTest extends TestCase
$this->assertFalse(FileHelper::validateName('test\testdat'));
$this->assertTrue(FileHelper::validateName('01test-test.dat'));
$this->assertFalse(FileHelper::validateName('test@test.dat'));
$this->assertFalse(FileHelper::validateName('test::test'));
$this->assertFalse(FileHelper::validateName('@test'));
}
public function testFormatIniString()