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

Fix possible recursive embeds in Dashboard text panels

Summary:
We currently detect tab panels embedding themselves, but do not detect text panels embedding themselves with `{Wxx}`.

Detect these self-embedding panels.

I had to add a bit of a hack to pass the parent panel PHIDs to the rule. Generally, I got the Markup API kind of wrong and want to update it, I'll file a followup with details about how I'd like to move forward.

Test Plan:
Created a text panel embedding itself, a tab panel embedding a text panel embedding itself, a tab panel embedding a text panel embedding the tab panel, etc.

Rendered all panels standalone and as `{Wxx}` from a different context.

{F761158}

{F761159}

{F761160}

{F761161}

{F761162}

Reviewers: chad, jbeta

Reviewed By: chad, jbeta

Differential Revision: https://secure.phabricator.com/D13999
This commit is contained in:
epriestley 2015-08-26 17:59:47 -07:00
parent 10966519e2
commit 55b44f53f8
3 changed files with 37 additions and 6 deletions

View file

@ -37,11 +37,25 @@ final class PhabricatorDashboardTextPanelType
PhabricatorDashboardPanelRenderingEngine $engine) {
$text = $panel->getProperty('text', '');
$oneoff = id(new PhabricatorMarkupOneOff())->setContent($text);
$field = 'default';
$text_content = PhabricatorMarkupEngine::renderOneObject(
id(new PhabricatorMarkupOneOff())->setContent($text),
'default',
$viewer);
// NOTE: We're taking extra steps here to prevent creation of a text panel
// which embeds itself using `{Wnnn}`, recursing indefinitely.
$parent_key = PhabricatorDashboardRemarkupRule::KEY_PARENT_PANEL_PHIDS;
$parent_phids = $engine->getParentPanelPHIDs();
$parent_phids[] = $panel->getPHID();
$markup_engine = id(new PhabricatorMarkupEngine())
->setViewer($viewer)
->setContextObject($panel)
->setAuxiliaryConfig($parent_key, $parent_phids);
$text_content = $markup_engine
->addObject($oneoff, $field)
->process()
->getOutput($oneoff, $field);
return id(new PHUIPropertyListView())
->addTextContent($text_content);

View file

@ -3,6 +3,8 @@
final class PhabricatorDashboardRemarkupRule
extends PhabricatorObjectRemarkupRule {
const KEY_PARENT_PANEL_PHIDS = 'dashboard.parentPanelPHIDs';
protected function getObjectNamePrefix() {
return 'W';
}
@ -21,12 +23,16 @@ final class PhabricatorDashboardRemarkupRule
PhabricatorObjectHandle $handle,
$options) {
$viewer = $this->getEngine()->getConfig('viewer');
$engine = $this->getEngine();
$viewer = $engine->getConfig('viewer');
$parent_key = self::KEY_PARENT_PANEL_PHIDS;
$parent_phids = $engine->getConfig($parent_key, array());
return id(new PhabricatorDashboardPanelRenderingEngine())
->setViewer($viewer)
->setPanel($object)
->setParentPanelPHIDs(array())
->setParentPanelPHIDs($parent_phids)
->renderPanel();
}

View file

@ -44,6 +44,7 @@ final class PhabricatorMarkupEngine extends Phobject {
private $contextObject;
private $version = 15;
private $engineCaches = array();
private $auxiliaryConfig = array();
/* -( Markup Pipeline )---------------------------------------------------- */
@ -122,6 +123,10 @@ final class PhabricatorMarkupEngine extends Phobject {
$engines[$key] = $info['object']->newMarkupEngine($info['field']);
$engines[$key]->setConfig('viewer', $this->viewer);
$engines[$key]->setConfig('contextObject', $this->contextObject);
foreach ($this->auxiliaryConfig as $aux_key => $aux_value) {
$engines[$key]->setConfig($aux_key, $aux_value);
}
}
// Load or build the preprocessor caches.
@ -310,6 +315,12 @@ final class PhabricatorMarkupEngine extends Phobject {
return $this;
}
public function setAuxiliaryConfig($key, $value) {
// TODO: This is gross and should be removed. Avoid use.
$this->auxiliaryConfig[$key] = $value;
return $this;
}
/* -( Engine Construction )------------------------------------------------ */