mirror of
https://we.phorge.it/source/phorge.git
synced 2024-12-12 08:36:13 +01:00
Rewrite regex for project names to be not prone to catastrophic backtracking
Summary: Fixes T15371 Test Plan: - Save the text `{{#translation:}}` in remarkup and see that it renders. - Create a project or projects with the hashtags `a`, `b`, `ab`, `foo`, `f.o.o`. - Observe that both before and after this patch you can link to all of them by hashtag. - Create a project or projects with the hashtags `a.`, `.b`, `.foo`, `foo.`. - Observe that both before and after this patch you can link to none of them by hashtag. Reviewers: O1 Blessed Committers, aklapper Reviewed By: O1 Blessed Committers, aklapper Subscribers: aklapper, tobiaswiese, valerio.bozzolan, Matthew, Cigaryno Maniphest Tasks: T15371 Differential Revision: https://we.phorge.it/D25838
This commit is contained in:
parent
48fd3f1c40
commit
9c73d62c44
1 changed files with 10 additions and 8 deletions
|
@ -22,8 +22,8 @@ final class ProjectRemarkupRule extends PhabricatorObjectRemarkupRule {
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function getObjectIDPattern() {
|
protected function getObjectIDPattern() {
|
||||||
// NOTE: The latter half of this rule matches monograms with internal
|
// NOTE: This rule matches monograms with internal periods,
|
||||||
// periods, like `#domain.com`, but does not match monograms with terminal
|
// like `#domain.com`, but does not match monograms with terminal
|
||||||
// periods, because they're probably just punctuation.
|
// periods, because they're probably just punctuation.
|
||||||
|
|
||||||
// Broadly, this will not match every possible project monogram, and we
|
// Broadly, this will not match every possible project monogram, and we
|
||||||
|
@ -39,12 +39,14 @@ final class ProjectRemarkupRule extends PhabricatorObjectRemarkupRule {
|
||||||
// These characters may not appear at the edge of the string.
|
// These characters may not appear at the edge of the string.
|
||||||
$never_edge = '.';
|
$never_edge = '.';
|
||||||
|
|
||||||
return
|
return '(?:'.
|
||||||
'[^'.$never_edge.$never.']+'.
|
// Short project name with one or two characters not in $never_edge or
|
||||||
'(?:'.
|
'[^'.$never_edge.$never.']{1,2}|'.
|
||||||
'[^'.$never.']*'.
|
// A single character not in $never or $never_edge,
|
||||||
'[^'.$never_edge.$never.']+'.
|
// then any number of characters not in $never then a single character
|
||||||
')*';
|
// not in $never or $never_edge
|
||||||
|
'[^'.$never_edge.$never.'][^'.$never.']+[^'.$never_edge.$never.']'.
|
||||||
|
')';
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function loadObjects(array $ids) {
|
protected function loadObjects(array $ids) {
|
||||||
|
|
Loading…
Reference in a new issue