Changeset View
Changeset View
Standalone View
Standalone View
src/applications/herald/adapter/HeraldAdapter.php
Show First 20 Lines • Show All 627 Lines • ▼ Show 20 Lines | switch ($condition_type) { | ||||
} | } | ||||
} | } | ||||
return false; | return false; | ||||
case self::CONDITION_REGEXP_PAIR: | case self::CONDITION_REGEXP_PAIR: | ||||
// Match a JSON-encoded pair of regular expressions against a | // Match a JSON-encoded pair of regular expressions against a | ||||
// dictionary. The first regexp must match the dictionary key, and the | // dictionary. The first regexp must match the dictionary key, and the | ||||
// second regexp must match the dictionary value. If any key/value pair | // second regexp must match the dictionary value. If any key/value pair | ||||
// in the dictionary matches both regexps, the condition is satisfied. | // in the dictionary matches both regexps, the condition is satisfied. | ||||
$regexp_pair = json_decode($condition_value, true); | $regexp_pair = null; | ||||
if (!is_array($regexp_pair)) { | try { | ||||
$regexp_pair = phutil_json_decode($condition_value); | |||||
} catch (PhutilJSONParserException $ex) { | |||||
throw new HeraldInvalidConditionException( | throw new HeraldInvalidConditionException( | ||||
'Regular expression pair is not valid JSON!'); | pht('Regular expression pair is not valid JSON!')); | ||||
} | } | ||||
if (count($regexp_pair) != 2) { | if (count($regexp_pair) != 2) { | ||||
throw new HeraldInvalidConditionException( | throw new HeraldInvalidConditionException( | ||||
'Regular expression pair is not a pair!'); | pht('Regular expression pair is not a pair!')); | ||||
} | } | ||||
$key_regexp = array_shift($regexp_pair); | $key_regexp = array_shift($regexp_pair); | ||||
$value_regexp = array_shift($regexp_pair); | $value_regexp = array_shift($regexp_pair); | ||||
foreach ((array)$field_value as $key => $value) { | foreach ((array)$field_value as $key => $value) { | ||||
$key_matches = @preg_match($key_regexp, $key); | $key_matches = @preg_match($key_regexp, $key); | ||||
if ($key_matches === false) { | if ($key_matches === false) { | ||||
▲ Show 20 Lines • Show All 48 Lines • ▼ Show 20 Lines | switch ($condition_type) { | ||||
pht( | pht( | ||||
'The regular expression "%s" is not valid. Regular expressions '. | 'The regular expression "%s" is not valid. Regular expressions '. | ||||
'must have enclosing characters (e.g. "@/path/to/file@", not '. | 'must have enclosing characters (e.g. "@/path/to/file@", not '. | ||||
'"/path/to/file") and be syntactically correct.', | '"/path/to/file") and be syntactically correct.', | ||||
$condition_value)); | $condition_value)); | ||||
} | } | ||||
break; | break; | ||||
case self::CONDITION_REGEXP_PAIR: | case self::CONDITION_REGEXP_PAIR: | ||||
$json = json_decode($condition_value, true); | $json = null; | ||||
if (!is_array($json)) { | try { | ||||
$json = phutil_json_decode($condition_value); | |||||
} catch (PhutilJSONParserException $ex) { | |||||
throw new HeraldInvalidConditionException( | throw new HeraldInvalidConditionException( | ||||
pht( | pht( | ||||
'The regular expression pair "%s" is not valid JSON. Enter a '. | 'The regular expression pair "%s" is not valid JSON. Enter a '. | ||||
'valid JSON array with two elements.', | 'valid JSON array with two elements.', | ||||
$condition_value)); | $condition_value)); | ||||
} | } | ||||
if (count($json) != 2) { | if (count($json) != 2) { | ||||
▲ Show 20 Lines • Show All 930 Lines • Show Last 20 Lines |