$this, FALSE, 0
);
+ 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();
$url = CRM_Utils_System::url('civicrm/admin/extensions', 'reset=1&action=browse');
$session->pushUserContext($url);
return ($key) ? CRM_Core_Key::valid($key) : FALSE;
}
+ /**
+ * @param string $key Extension Key to check
+ * @return bool
+ */
+ public static function checkExtensionKeyIsValid($key = NULL) {
+
+ if (!empty($key) && !preg_match('/^[0-9a-zA-Z._-]+$/', $key)) {
+ return FALSE;
+ }
+ return TRUE;
+ }
+
}
}
break;
+ case 'ExtensionKey':
+ if (CRM_Utils_Rule::checkExtensionKeyIsValid($data)) {
+ return $data;
+ }
+ break;
+
default:
CRM_Core_Error::fatal("Cannot recognize $type for $data");
break;
);
}
+ /**
+ * @return array
+ */
+ public function extensionKeyTests() {
+ $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 extensionKeyTests
+ */
+ public function testExtensionKeyValid($key, $expectedResult) {
+ $this->assertEquals($expectedResult, CRM_Utils_Rule::checkExtensionKeyIsValid($key));
+ }
+
}