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:
parent
2a063a93a9
commit
2f7010d18e
2 changed files with 24 additions and 17 deletions
|
@ -20,17 +20,13 @@ final class ProjectRemarkupRule extends PhabricatorObjectRemarkupRule {
|
|||
}
|
||||
|
||||
protected function getObjectIDPattern() {
|
||||
// NOTE: This explicitly does not match strings which contain only
|
||||
// digits, because digit strings like "#123" are used to reference tasks at
|
||||
// Facebook and are somewhat conventional in general.
|
||||
|
||||
// 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.
|
||||
// NOTE: 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
|
||||
// accept some false negatives -- like `#1` or `#dot.` -- in order to avoid
|
||||
// a bunch of false positives on general use of the `#` character.
|
||||
// accept some false negatives -- like `#dot.` -- in order to avoid a bunch
|
||||
// of false positives on general use of the `#` character.
|
||||
|
||||
// In other contexts, the PhabricatorProjectProjectPHIDType pattern is
|
||||
// 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.
|
||||
$never = '\s?!,:;{}#\\(\\)"\'';
|
||||
|
||||
// These characters may not appear at the beginning.
|
||||
$never_first = '.\d';
|
||||
|
||||
// These characters may not appear at the end.
|
||||
$never_last = '.';
|
||||
// These characters may not appear at the edge of the string.
|
||||
$never_edge = '.';
|
||||
|
||||
return
|
||||
'[^'.$never_first.$never.']+'.
|
||||
'[^'.$never_edge.$never.']+'.
|
||||
'(?:'.
|
||||
'[^'.$never.']*'.
|
||||
'[^'.$never_last.$never.']+'.
|
||||
'[^'.$never_edge.$never.']+'.
|
||||
')*';
|
||||
}
|
||||
|
||||
|
|
|
@ -33,7 +33,21 @@ final class ProjectRemarkupRuleTestCase extends PhabricatorTestCase {
|
|||
),
|
||||
'#123' => 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(
|
||||
'embed' => array(),
|
||||
|
|
Loading…
Reference in a new issue