Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F2889420
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Award Token
Flag For Later
Advanced/Developer...
View Handle
View Hovercard
Size
5 KB
Referenced Files
None
Subscribers
None
View Options
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
@@ -1,73 +1,83 @@
<?php
final class ManiphestCustomFieldStatusParserTestCase
extends PhabricatorTestCase {
public function testParser() {
$map = array(
'quack quack quack' => array(),
'T123' => array(),
'Fixes T123' => array(
array(
'match' => 'Fixes T123',
'prefix' => 'Fixes',
'infix' => '',
'monograms' => array('T123'),
'suffix' => '',
'offset' => 0,
),
),
'Fixes T123, T124, and also some other bugs.' => array(
array(
'match' => 'Fixes T123, T124, ',
'prefix' => 'Fixes',
'infix' => '',
'monograms' => array('T123', 'T124'),
'suffix' => '',
'offset' => 0,
),
),
'Closes T1 as wontfix' => array(
array(
'match' => 'Closes T1 as wontfix',
'prefix' => 'Closes',
'infix' => '',
'monograms' => array('T1'),
'suffix' => 'as wontfix',
'offset' => 0,
),
),
'Fixes task T9' => array(
array(
'match' => 'Fixes task T9',
'prefix' => 'Fixes',
'infix' => 'task',
'monograms' => array('T9'),
'suffix' => '',
'offset' => 0,
),
),
'Fixes t2apps' => array(),
'fixes a bug' => array(),
'Prefixes T2' => array(),
'Reopens T123' => array(
array(
'match' => 'Reopens T123',
'prefix' => 'Reopens',
'infix' => '',
'monograms' => array('T123'),
'suffix' => '',
'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) {
$parser = new ManiphestCustomFieldStatusParser();
$output = $parser->parseCorpus($input);
$this->assertEqual($expect, $output, $input);
}
}
}
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
@@ -1,71 +1,78 @@
<?php
abstract class PhabricatorCustomFieldMonogramParser
extends Phobject {
abstract protected function getPrefixes();
abstract protected function getSuffixes();
abstract protected function getInfixes();
abstract protected function getMonogramPattern();
public function parseCorpus($corpus) {
$prefixes = $this->getPrefixes();
$suffixes = $this->getSuffixes();
$infixes = $this->getInfixes();
$prefix_regex = $this->buildRegex($prefixes);
$infix_regex = $this->buildRegex($infixes, true);
$suffix_regex = $this->buildRegex($suffixes, true, true);
$monogram_pattern = $this->getMonogramPattern();
$pattern =
'/'.
'(?:^|\b)'.
$prefix_regex.
$infix_regex.
'((?:'.$monogram_pattern.'[,\s]*)+)'.
+ '(?:\band\s+('.$monogram_pattern.'))?'.
$suffix_regex.
'(?:$|\b)'.
'/';
$matches = null;
$ok = preg_match_all(
$pattern,
$corpus,
$matches,
PREG_SET_ORDER | PREG_OFFSET_CAPTURE);
if ($ok === false) {
throw new Exception(pht('Regular expression "%s" is invalid!', $pattern));
}
$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],
);
}
return $results;
}
private function buildRegex(array $list, $optional = false, $final = false) {
$parts = array();
foreach ($list as $string) {
$parts[] = preg_quote($string, '/');
}
$parts = implode('|', $parts);
$maybe_tail = $final ? '' : '\s+';
$maybe_optional = $optional ? '?' : '';
return '(?i:('.$parts.')'.$maybe_tail.')'.$maybe_optional;
}
}
File Metadata
Details
Attached
Mime Type
text/x-diff
Expires
Jan 19 2025, 12:08 (4 w, 4 d ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
1124403
Default Alt Text
(5 KB)
Attached To
Mode
rP Phorge
Attached
Detach File
Event Timeline
Log In to Comment