Changeset View
Changeset View
Standalone View
Standalone View
src/applications/repository/editor/PhabricatorRepositoryEditor.php
Show First 20 Lines • Show All 319 Lines • ▼ Show 20 Lines | final class PhabricatorRepositoryEditor | ||||
protected function validateTransaction( | protected function validateTransaction( | ||||
PhabricatorLiskDAO $object, | PhabricatorLiskDAO $object, | ||||
$type, | $type, | ||||
array $xactions) { | array $xactions) { | ||||
$errors = parent::validateTransaction($object, $type, $xactions); | $errors = parent::validateTransaction($object, $type, $xactions); | ||||
switch ($type) { | switch ($type) { | ||||
case PhabricatorRepositoryTransaction::TYPE_AUTOCLOSE: | |||||
case PhabricatorRepositoryTransaction::TYPE_TRACK_ONLY: | |||||
foreach ($xactions as $xaction) { | |||||
foreach ($xaction->getNewValue() as $pattern) { | |||||
// Check for invalid regular expressions. | |||||
$regexp = PhabricatorRepository::extractBranchRegexp($pattern); | |||||
if ($regexp !== null) { | |||||
$ok = @preg_match($regexp, ''); | |||||
if ($ok === false) { | |||||
$error = new PhabricatorApplicationTransactionValidationError( | |||||
$type, | |||||
pht('Invalid'), | |||||
pht( | |||||
'Expression "%s" is not a valid regular expression. Note '. | |||||
'that you must include delimiters.', | |||||
$regexp), | |||||
$xaction); | |||||
$errors[] = $error; | |||||
continue; | |||||
} | |||||
} | |||||
// Check for formatting mistakes like `regex(...)` instead of | |||||
// `regexp(...)`. | |||||
$matches = null; | |||||
if (preg_match('/^([^(]+)\\(.*\\)\z/', $pattern, $matches)) { | |||||
switch ($matches[1]) { | |||||
case 'regexp': | |||||
break; | |||||
default: | |||||
$error = new PhabricatorApplicationTransactionValidationError( | |||||
$type, | |||||
pht('Invalid'), | |||||
pht( | |||||
'Matching function "%s(...)" is not recognized. Valid '. | |||||
'functions are: regexp(...).', | |||||
$matches[1]), | |||||
$xaction); | |||||
$errors[] = $error; | |||||
break; | |||||
} | |||||
} | |||||
} | |||||
} | |||||
break; | |||||
case PhabricatorRepositoryTransaction::TYPE_REMOTE_URI: | case PhabricatorRepositoryTransaction::TYPE_REMOTE_URI: | ||||
foreach ($xactions as $xaction) { | foreach ($xactions as $xaction) { | ||||
$new_uri = $xaction->getNewValue(); | $new_uri = $xaction->getNewValue(); | ||||
try { | try { | ||||
PhabricatorRepository::assertValidRemoteURI($new_uri); | PhabricatorRepository::assertValidRemoteURI($new_uri); | ||||
} catch (Exception $ex) { | } catch (Exception $ex) { | ||||
$errors[] = new PhabricatorApplicationTransactionValidationError( | $errors[] = new PhabricatorApplicationTransactionValidationError( | ||||
$type, | $type, | ||||
Show All 29 Lines |