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('*****@*****.**')); }
/** * Executes the page, layout, component and plugin AJAX handlers. * @return mixed Returns the AJAX Response object or null. */ protected function execAjaxHandlers() { if ($handler = trim(Request::header('X_OCTOBER_REQUEST_HANDLER'))) { try { /* * Validate the handler name */ if (!preg_match('/^(?:\\w+\\:{2})?on[A-Z]{1}[\\w+]*$/', $handler)) { throw new CmsException(Lang::get('cms::lang.ajax_handler.invalid_name', ['name' => $handler])); } /* * Validate the handler partial list */ if ($partialList = trim(Request::header('X_OCTOBER_REQUEST_PARTIALS'))) { $partialList = explode('&', $partialList); foreach ($partialList as $partial) { if (!CmsFileHelper::validateName($partial)) { throw new CmsException(Lang::get('cms::lang.partial.invalid_name', ['name' => $partial])); } } } else { $partialList = []; } $responseContents = []; /* * Execute the handler */ if (!($result = $this->runAjaxHandler($handler))) { throw new CmsException(Lang::get('cms::lang.ajax_handler.not_found', ['name' => $handler])); } /* * If the handler returned an array, we should add it to output for rendering. * If it is a string, add it to the array with the key "result". */ if (is_array($result)) { $responseContents = array_merge($responseContents, $result); } elseif (is_string($result)) { $responseContents['result'] = $result; } /* * Render partials and return the response as array that will be converted to JSON automatically. */ foreach ($partialList as $partial) { $responseContents[$partial] = $this->renderPartial($partial); } /* * If the handler returned a redirect, process it so framework.js knows to redirect * the browser and not the request! */ if ($result instanceof RedirectResponse) { $responseContents['X_OCTOBER_REDIRECT'] = $result->getTargetUrl(); } return Response::make()->setContent($responseContents); } catch (ValidationException $ex) { /* * Handle validation errors */ $responseContents['X_OCTOBER_ERROR_FIELDS'] = $ex->getFields(); $responseContents['X_OCTOBER_ERROR_MESSAGE'] = $ex->getMessage(); return Response::make($responseContents, 406); } catch (Exception $ex) { return Response::make($ex->getMessage(), 500); } } return null; }