From 6bebb3c69a07ce045b2bf997154927a5f0efb7af Mon Sep 17 00:00:00 2001 From: Joshua Spence Date: Tue, 5 May 2015 07:11:53 +1000 Subject: [PATCH] Add "and" support to "ref" Summary: Fixes T8038. Allow `PhabricatorCustomFieldMonogramParser` to handle "and". This means that `Ref Tx, Ty and Tz` will correctly return `array('monograms' => array('Tx', 'Ty', 'Tz')`. Test Plan: Added unit tests. Reviewers: epriestley, #blessed_reviewers Reviewed By: epriestley, #blessed_reviewers Subscribers: epriestley Maniphest Tasks: T2, T3, T1, T8038 Differential Revision: https://secure.phabricator.com/D12682 --- .../ManiphestCustomFieldStatusParserTestCase.php | 10 ++++++++++ .../parser/PhabricatorCustomFieldMonogramParser.php | 11 +++++++++-- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/src/applications/maniphest/field/parser/__tests__/ManiphestCustomFieldStatusParserTestCase.php b/src/applications/maniphest/field/parser/__tests__/ManiphestCustomFieldStatusParserTestCase.php index cd64c23d29..5dc15673b9 100644 --- a/src/applications/maniphest/field/parser/__tests__/ManiphestCustomFieldStatusParserTestCase.php +++ b/src/applications/maniphest/field/parser/__tests__/ManiphestCustomFieldStatusParserTestCase.php @@ -60,6 +60,16 @@ final class ManiphestCustomFieldStatusParserTestCase 'offset' => 0, ), ), + 'Fixes T123, T456, and T789.' => array( + array( + 'match' => 'Fixes T123, T456, and T789', + 'prefix' => 'Fixes', + 'infix' => '', + 'monograms' => array('T123', 'T456', 'T789'), + 'suffix' => '', + 'offset' => 0, + ), + ), ); foreach ($map as $input => $expect) { diff --git a/src/infrastructure/customfield/parser/PhabricatorCustomFieldMonogramParser.php b/src/infrastructure/customfield/parser/PhabricatorCustomFieldMonogramParser.php index c26a4e16f0..48e922dc62 100644 --- a/src/infrastructure/customfield/parser/PhabricatorCustomFieldMonogramParser.php +++ b/src/infrastructure/customfield/parser/PhabricatorCustomFieldMonogramParser.php @@ -25,6 +25,7 @@ abstract class PhabricatorCustomFieldMonogramParser $prefix_regex. $infix_regex. '((?:'.$monogram_pattern.'[,\s]*)+)'. + '(?:\band\s+('.$monogram_pattern.'))?'. $suffix_regex. '(?:$|\b)'. '/'; @@ -42,12 +43,18 @@ abstract class PhabricatorCustomFieldMonogramParser $results = array(); foreach ($matches as $set) { + $monograms = array_filter(preg_split('/[,\s]+/', $set[3][0])); + + if (isset($set[4]) && $set[4][0]) { + $monograms[] = $set[4][0]; + } + $results[] = array( 'match' => $set[0][0], 'prefix' => $set[1][0], 'infix' => $set[2][0], - 'monograms' => array_filter(preg_split('/[,\s]+/', $set[3][0])), - 'suffix' => idx(idx($set, 4, array()), 0, ''), + 'monograms' => $monograms, + 'suffix' => idx(idx($set, 5, array()), 0, ''), 'offset' => $set[0][1], ); } -- 2.51.2