1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-19 13:22:42 +01:00

Markup project hashtags which begin with (or contain only) digits

Summary:
Fixes T9832. We currently refuse to recognize project hashtags in remarkup if they begin with a digit. This is motivated by attempting to not recognize them if they contain only digits.

I don't think we really gain anything by this. Although most `#123` in text are probably not project references, the cost of doing a lookup for them is quite small, and //some// of them are.

In cases where users use `#123` to refer to tasks in an external system, they can use a rule for that with higher precedence than this one or not give their projects conflicting hashtags.

Test Plan:
  - This is well-covered by unit tests.
  - Referenced a `#3u1`, per T9832.

Reviewers: chad

Reviewed By: chad

Maniphest Tasks: T9832

Differential Revision: https://secure.phabricator.com/D14547
This commit is contained in:
epriestley 2015-11-23 05:51:14 -08:00
parent 2a063a93a9
commit 2f7010d18e
2 changed files with 24 additions and 17 deletions

View file

@ -20,17 +20,13 @@ final class ProjectRemarkupRule extends PhabricatorObjectRemarkupRule {
} }
protected function getObjectIDPattern() { protected function getObjectIDPattern() {
// NOTE: This explicitly does not match strings which contain only // NOTE: The latter half of this rule matches monograms with internal
// digits, because digit strings like "#123" are used to reference tasks at // periods, like `#domain.com`, but does not match monograms with terminal
// Facebook and are somewhat conventional in general. // periods, because they're probably just puncutation.
// The latter half of this rule matches monograms with internal periods,
// like `#domain.com`, but does not match monograms with terminal periods,
// because they're probably just puncutation.
// Broadly, this will not match every possible project monogram, and we // Broadly, this will not match every possible project monogram, and we
// accept some false negatives -- like `#1` or `#dot.` -- in order to avoid // accept some false negatives -- like `#dot.` -- in order to avoid a bunch
// a bunch of false positives on general use of the `#` character. // of false positives on general use of the `#` character.
// In other contexts, the PhabricatorProjectProjectPHIDType pattern is // In other contexts, the PhabricatorProjectProjectPHIDType pattern is
// controlling and these names should parse correctly. // controlling and these names should parse correctly.
@ -38,17 +34,14 @@ final class ProjectRemarkupRule extends PhabricatorObjectRemarkupRule {
// These characters may never appear anywhere in a hashtag. // These characters may never appear anywhere in a hashtag.
$never = '\s?!,:;{}#\\(\\)"\''; $never = '\s?!,:;{}#\\(\\)"\'';
// These characters may not appear at the beginning. // These characters may not appear at the edge of the string.
$never_first = '.\d'; $never_edge = '.';
// These characters may not appear at the end.
$never_last = '.';
return return
'[^'.$never_first.$never.']+'. '[^'.$never_edge.$never.']+'.
'(?:'. '(?:'.
'[^'.$never.']*'. '[^'.$never.']*'.
'[^'.$never_last.$never.']+'. '[^'.$never_edge.$never.']+'.
')*'; ')*';
} }

View file

@ -33,7 +33,21 @@ final class ProjectRemarkupRuleTestCase extends PhabricatorTestCase {
), ),
'#123' => array( '#123' => array(
'embed' => array(), 'embed' => array(),
'ref' => array(), 'ref' => array(
array(
'offset' => 1,
'id' => '123',
),
),
),
'#2x4' => array(
'embed' => array(),
'ref' => array(
array(
'offset' => 1,
'id' => '2x4',
),
),
), ),
'#security#123' => array( '#security#123' => array(
'embed' => array(), 'embed' => array(),