*/
class CRM_Admin_Form_Extensions extends CRM_Admin_Form {
- /**
- * @param string $key Extension Key to check
- * @return bool
- */
- public static function checkExtesnionKeyIsValid($key = NULL) {
- if (!empty($key) && !preg_match('/^[0-9a-zA-Z._-]+$/', $key)) {
- return FALSE;
- }
- return TRUE;
- }
-
/**
* Form pre-processing.
*/
$this->_key = CRM_Utils_Request::retrieve('key', 'String',
$this, FALSE, 0
);
- if (!self::checkExtesnionKeyIsValid($this->_key)) {
+ if (!CRM_Utils_Type::validate($this->_key, 'ExtensionKey')) {
throw new CRM_Core_Exception('Extension Key does not match expected standard');
}
$session = CRM_Core_Session::singleton();
}
}
+ /**
+ * @param string $key Extension Key to check
+ * @return bool
+ */
+ public static function checkExtesnionKeyIsValid($key = NULL) {
+ if (!empty($key) && !preg_match('/^[0-9a-zA-Z._-]+$/', $key)) {
+ return FALSE;
+ }
+ return TRUE;
+ }
+
}
}
break;
+ case 'ExtensionKey':
+ if (CRM_Utils_Rule::checkExtesnionKeyIsValid($data)) {
+ return $data;
+ }
+ break;
+
default:
CRM_Core_Error::fatal("Cannot recognize $type for $data");
break;
+++ /dev/null
-<?php
-
-/**
- * Class CRM_Admin_Form_ExtensionTest
- * @group headless
- */
-class CRM_Admin_Form_ExtensionTest extends CiviUnitTestCase {
-
- /**
- * @return array
- */
- public function extenionKeyTests() {
- $keys = array();
- $keys[] = array('org.civicrm.multisite');
- $keys[] = array('au.org.contribute2016');
- $keys[] = array('%3Csvg%20onload=alert(0)%3E');
- return $keys;
- }
-
- /**
- * @param $key
- * @dataProvider extenionKeyTests
- */
- public function testExtenionKeyValid($key) {
- if ($key == '%3Csvg%20onload=alert(0)%3E') {
- $this->assertFalse(CRM_Admin_Form_Extensions::checkExtesnionKeyIsValid($key));
- }
- else {
- $this->assertTrue(CRM_Admin_Form_Extensions::checkExtesnionKeyIsValid($key));
- }
- }
-
-}
);
}
+ /**
+ * @return array
+ */
+ public function extenionKeyTests() {
+ $keys = array();
+ $keys[] = array('org.civicrm.multisite', TRUE);
+ $keys[] = array('au.org.contribute2016', TRUE);
+ $keys[] = array('%3Csvg%20onload=alert(0)%3E', FALSE);
+ return $keys;
+ }
+
+ /**
+ * @param $key
+ * @param $expectedResult
+ * @dataProvider extenionKeyTests
+ */
+ public function testExtenionKeyValid($key, $expectedResult) {
+ $this->assertEquals($expectedResult, CRM_Utils_Rule::checkExtesnionKeyIsValid($key));
+ }
+
}