Skip to content

Commit 059920c

Browse files
author
vrana
committed
Convert AphrontErrorView to safe HTML
Summary: Done by searching for `AphrontErrorView` and then `appendChild()`. Test Plan: Looked at Commit Detail. Looked at Revision Detail. Reviewers: epriestley Reviewed By: epriestley CC: aran, Korvin Maniphest Tasks: T2432 Differential Revision: https://secure.phabricator.com/D4843
1 parent 11bb8db commit 059920c

File tree

31 files changed

+152
-141
lines changed

31 files changed

+152
-141
lines changed

src/aphront/configuration/AphrontDefaultApplicationConfiguration.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ public function handleException(Exception $ex) {
211211
if ($ex instanceof AphrontUsageException) {
212212
$error = new AphrontErrorView();
213213
$error->setTitle(phutil_escape_html($ex->getTitle()));
214-
$error->appendChild(phutil_escape_html($ex->getMessage()));
214+
$error->appendChild($ex->getMessage());
215215

216216
$view = new PhabricatorStandardPageView();
217217
$view->setRequest($this->getRequest());

src/aphront/response/AphrontRedirectResponse.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,11 @@ public function buildResponseString() {
4949
),
5050
'Continue to: '.$this->getURI());
5151

52-
$error->appendChild(
52+
$error->appendChild(hsprintf(
5353
'<p>You were stopped here because <tt>debug.stop-on-redirect</tt> '.
5454
'is set in your configuration.</p>'.
55-
'<p>'.$link.'</p>');
55+
'<p>%s</p>',
56+
$link));
5657

5758
$view->appendChild($error);
5859

src/applications/auth/controller/PhabricatorMustVerifyEmailController.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,12 @@ public function processRequest() {
3131
$sent = new AphrontErrorView();
3232
$sent->setSeverity(AphrontErrorView::SEVERITY_NOTICE);
3333
$sent->setTitle(pht('Email Sent'));
34-
$sent->appendChild('<p>'.
35-
pht('Another verification email was sent to <strong>%s</strong>.',
36-
phutil_escape_html($email_address)).'</p>');
34+
$sent->appendChild(phutil_tag(
35+
'p',
36+
array(),
37+
pht(
38+
'Another verification email was sent to %s.',
39+
phutil_tag('strong', array(), $email_address))));
3740
}
3841

3942
$error_view = new AphrontRequestFailureView();

src/applications/conduit/controller/PhabricatorConduitConsoleController.php

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -35,20 +35,16 @@ public function processRequest() {
3535
case ConduitAPIMethod::METHOD_STATUS_DEPRECATED:
3636
$status_view->setTitle('Deprecated Method');
3737
$status_view->appendChild(
38-
phutil_escape_html(
39-
nonempty(
40-
$reason,
41-
"This method is deprecated.")));
38+
nonempty($reason, "This method is deprecated."));
4239
break;
4340
case ConduitAPIMethod::METHOD_STATUS_UNSTABLE:
4441
$status_view->setSeverity(AphrontErrorView::SEVERITY_WARNING);
4542
$status_view->setTitle('Unstable Method');
4643
$status_view->appendChild(
47-
phutil_escape_html(
48-
nonempty(
49-
$reason,
50-
"This method is new and unstable. Its interface is subject ".
51-
"to change.")));
44+
nonempty(
45+
$reason,
46+
"This method is new and unstable. Its interface is subject ".
47+
"to change."));
5248
break;
5349
}
5450
}

src/applications/config/controller/PhabricatorConfigEditController.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ public function processRequest() {
108108
$error_view = id(new AphrontErrorView())
109109
->setTitle(pht('Configuration Hidden'))
110110
->setSeverity(AphrontErrorView::SEVERITY_WARNING)
111-
->appendChild('<p>'.phutil_escape_html($msg).'</p>');
111+
->appendChild(phutil_tag('p', array(), $msg));
112112
} else if ($option->getLocked()) {
113113
$msg = pht(
114114
"This configuration is locked and can not be edited from the web ".
@@ -117,7 +117,7 @@ public function processRequest() {
117117
$error_view = id(new AphrontErrorView())
118118
->setTitle(pht('Configuration Locked'))
119119
->setSeverity(AphrontErrorView::SEVERITY_NOTICE)
120-
->appendChild('<p>'.phutil_escape_html($msg).'</p>');
120+
->appendChild(phutil_tag('p', array(), $msg));
121121
}
122122

123123
if ($option->getHidden()) {

src/applications/daemon/controller/PhabricatorWorkerTaskDetailController.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,10 @@ public function processRequest() {
2323

2424
$error_view = new AphrontErrorView();
2525
$error_view->setTitle('No Such Task');
26-
$error_view->appendChild(
27-
'<p>This task may have recently been garbage collected.</p>');
26+
$error_view->appendChild(phutil_tag(
27+
'p',
28+
array(),
29+
'This task may have recently been garbage collected.'));
2830
$error_view->setSeverity(AphrontErrorView::SEVERITY_NODATA);
2931

3032
$content = $error_view;

src/applications/differential/controller/DifferentialRevisionViewController.php

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -180,21 +180,20 @@ public function processRequest() {
180180
$warning = new AphrontErrorView();
181181
$warning->setTitle('Very Large Diff');
182182
$warning->setSeverity(AphrontErrorView::SEVERITY_WARNING);
183-
$warning->appendChild(
183+
$warning->appendChild(hsprintf(
184+
'%s <strong>%s</strong>',
184185
pht(
185186
'This diff is very large and affects %s files. Load each file '.
186187
'individually.',
187-
new PhutilNumber($count)).
188-
" <strong>".
189-
phutil_tag(
190-
'a',
191-
array(
192-
'href' => $request_uri
193-
->alter('large', 'true')
194-
->setFragment('toc'),
195-
),
196-
pht('Show All Files Inline')).
197-
"</strong>");
188+
new PhutilNumber($count)),
189+
phutil_tag(
190+
'a',
191+
array(
192+
'href' => $request_uri
193+
->alter('large', 'true')
194+
->setFragment('toc'),
195+
),
196+
pht('Show All Files Inline'))));
198197
$warning = $warning->render();
199198

200199
$my_inlines = id(new DifferentialInlineComment())->loadAllWhere(

src/applications/differential/field/specification/DifferentialLintFieldSpecification.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -245,24 +245,24 @@ public function renderWarningBoxForRevisionAccept() {
245245

246246
if ($status == DifferentialLintStatus::LINT_SKIP) {
247247
$content =
248-
"<p>This diff was created without running lint. Make sure you are ".
249-
"OK with that before you accept this diff.</p>";
248+
"This diff was created without running lint. Make sure you are ".
249+
"OK with that before you accept this diff.";
250250

251251
} else if ($status == DifferentialLintStatus::LINT_POSTPONED) {
252252
$severity = AphrontErrorView::SEVERITY_WARNING;
253253
$content =
254-
"<p>Postponed linters didn't finish yet. Make sure you are OK with ".
255-
"that before you accept this diff.</p>";
254+
"Postponed linters didn't finish yet. Make sure you are OK with ".
255+
"that before you accept this diff.";
256256

257257
} else {
258258
$content =
259-
"<p>This diff has Lint Problems. Make sure you are OK with them ".
260-
"before you accept this diff.</p>";
259+
"This diff has Lint Problems. Make sure you are OK with them ".
260+
"before you accept this diff.";
261261
}
262262

263263
return id(new AphrontErrorView())
264264
->setSeverity($severity)
265-
->appendChild($content)
265+
->appendChild(phutil_tag('p', array(), $content))
266266
->setTitle(idx($titles, $status, 'Warning'));
267267
}
268268

src/applications/differential/field/specification/DifferentialUnitFieldSpecification.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -200,21 +200,21 @@ public function renderWarningBoxForRevisionAccept() {
200200
);
201201
if ($diff->getUnitStatus() == DifferentialUnitStatus::UNIT_POSTPONED) {
202202
$content =
203-
"<p>This diff has postponed unit tests. The results should be ".
203+
"This diff has postponed unit tests. The results should be ".
204204
"coming in soon. You should probably wait for them before accepting ".
205-
"this diff.</p>";
205+
"this diff.";
206206
} else if ($diff->getUnitStatus() == DifferentialUnitStatus::UNIT_SKIP) {
207207
$content =
208-
"<p>Unit tests were skipped when this diff was created. Make sure ".
209-
"you are OK with that before you accept this diff.</p>";
208+
"Unit tests were skipped when this diff was created. Make sure ".
209+
"you are OK with that before you accept this diff.";
210210
} else {
211211
$content =
212-
"<p>This diff has Unit Test Problems. Make sure you are OK with ".
213-
"them before you accept this diff.</p>";
212+
"This diff has Unit Test Problems. Make sure you are OK with ".
213+
"them before you accept this diff.";
214214
}
215215
$unit_warning = id(new AphrontErrorView())
216216
->setSeverity(AphrontErrorView::SEVERITY_ERROR)
217-
->appendChild($content)
217+
->appendChild(phutil_tag('p', array(), $content))
218218
->setTitle(idx($titles, $diff->getUnitStatus(), 'Warning'));
219219
}
220220
return $unit_warning;

src/applications/differential/view/DifferentialAddCommentView.php

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -46,21 +46,6 @@ public function setCCs(array $names) {
4646
return $this;
4747
}
4848

49-
private function generateWarningView(
50-
$status,
51-
array $titles,
52-
$id,
53-
$content) {
54-
55-
$warning = new AphrontErrorView();
56-
$warning->setSeverity(AphrontErrorView::SEVERITY_ERROR);
57-
$warning->setID($id);
58-
$warning->appendChild($content);
59-
$warning->setTitle(idx($titles, $status, 'Warning'));
60-
61-
return $warning;
62-
}
63-
6449
public function render() {
6550

6651
require_celerity_resource('differential-revision-add-comment-css');

src/applications/diffusion/controller/DiffusionBrowseFileController.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,8 @@ public function processRequest() {
9696
$notice->setSeverity(AphrontErrorView::SEVERITY_NOTICE);
9797
$notice->setTitle('File Renamed');
9898
$notice->appendChild(
99-
"File history passes through a rename from '".
100-
phutil_escape_html($drequest->getPath())."' to '".
101-
phutil_escape_html($renamed)."'.");
99+
"File history passes through a rename from '".$drequest->getPath().
100+
"' to '".$renamed."'.");
102101
$content[] = $notice;
103102
}
104103

src/applications/diffusion/controller/DiffusionCommitController.php

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,8 @@ public function processRequest() {
6262
$error_panel->appendChild(
6363
"This Diffusion repository is configured to track only one ".
6464
"subdirectory of the entire Subversion repository, and this commit ".
65-
"didn't affect the tracked subdirectory ('".
66-
phutil_escape_html($subpath)."'), so no information is available.");
65+
"didn't affect the tracked subdirectory ('".$subpath."'), so no ".
66+
"information is available.");
6767
$content[] = $error_panel;
6868
$content[] = $top_anchor;
6969
} else {
@@ -162,8 +162,7 @@ public function processRequest() {
162162
if ($bad_commit) {
163163
$error_panel = new AphrontErrorView();
164164
$error_panel->setTitle('Bad Commit');
165-
$error_panel->appendChild(
166-
phutil_escape_html($bad_commit['description']));
165+
$error_panel->appendChild($bad_commit['description']);
167166

168167
$content[] = $error_panel;
169168
} else if ($is_foreign) {
@@ -207,8 +206,10 @@ public function processRequest() {
207206
$warning_view = id(new AphrontErrorView())
208207
->setSeverity(AphrontErrorView::SEVERITY_WARNING)
209208
->setTitle('Very Large Commit')
210-
->appendChild(
211-
"<p>This commit is very large. Load each file individually.</p>");
209+
->appendChild(phutil_tag(
210+
'p',
211+
array(),
212+
"This commit is very large. Load each file individually."));
212213

213214
$change_panel->appendChild($warning_view);
214215
$change_panel->addButton($show_all_button);

src/applications/diffusion/controller/DiffusionExternalController.php

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,17 +60,19 @@ public function processRequest() {
6060
if (empty($commits)) {
6161
$desc = null;
6262
if ($uri) {
63-
$desc = phutil_escape_html($uri).', at ';
63+
$desc = $uri.', at ';
6464
}
65-
$desc .= phutil_escape_html($id);
65+
$desc .= $id;
6666

6767
$content = id(new AphrontErrorView())
6868
->setTitle('Unknown External')
6969
->setSeverity(AphrontErrorView::SEVERITY_WARNING)
70-
->appendChild(
71-
"<p>This external ({$desc}) does not appear in any tracked ".
70+
->appendChild(phutil_tag(
71+
'p',
72+
array(),
73+
"This external ({$desc}) does not appear in any tracked ".
7274
"repository. It may exist in an untracked repository that ".
73-
"Diffusion does not know about.</p>");
75+
"Diffusion does not know about."));
7476
} else if (count($commits) == 1) {
7577
$commit = head($commits);
7678
$repo = $repositories[$commit->getRepositoryID()];

src/applications/diffusion/view/DiffusionEmptyResultView.php

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,6 @@ public function render() {
4343
$deleted = $this->browseQuery->getDeletedAtCommit();
4444
$existed = $this->browseQuery->getExistedAtCommit();
4545

46-
$deleted = self::linkCommit($drequest->getRepository(), $deleted);
47-
4846
$browse = $this->linkBrowse(
4947
$drequest->getPath(),
5048
array(
@@ -54,19 +52,22 @@ public function render() {
5452
)
5553
);
5654

57-
$existed = "r{$callsign}{$existed}";
58-
5955
$title = 'Path Was Deleted';
60-
$body = "This path does not exist at {$commit}. It was deleted in ".
61-
"{$deleted} and last {$browse} at {$existed}.";
56+
$body = hsprintf(
57+
"This path does not exist at %s. It was deleted in %s and last %s ".
58+
"at %s.",
59+
$commit,
60+
self::linkCommit($drequest->getRepository(), $deleted),
61+
$browse,
62+
"r{$callsign}{$existed}");
6263
$severity = AphrontErrorView::SEVERITY_WARNING;
6364
break;
6465
case DiffusionBrowseQuery::REASON_IS_UNTRACKED_PARENT:
6566
$subdir = $drequest->getRepository()->getDetail('svn-subpath');
6667
$title = 'Directory Not Tracked';
6768
$body =
6869
"This repository is configured to track only one subdirectory ".
69-
"of the entire repository ('".phutil_escape_html($subdir)."'), ".
70+
"of the entire repository ('{$subdir}'), ".
7071
"but you aren't looking at something in that subdirectory, so no ".
7172
"information is available.";
7273
$severity = AphrontErrorView::SEVERITY_WARNING;
@@ -78,7 +79,7 @@ public function render() {
7879
$error_view = new AphrontErrorView();
7980
$error_view->setSeverity($severity);
8081
$error_view->setTitle($title);
81-
$error_view->appendChild('<p>'.$body.'</p>');
82+
$error_view->appendChild(phutil_tag('p', array(), $body));
8283

8384
return $error_view->render();
8485
}

src/applications/fact/controller/PhabricatorFactHomeController.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,10 @@ private function buildChartForm() {
9494
return id(new AphrontErrorView())
9595
->setSeverity(AphrontErrorView::SEVERITY_NOTICE)
9696
->setTitle(pht('No Chartable Facts'))
97-
->appendChild(
98-
'<p>'.pht(
99-
'There are no facts that can be plotted yet.').'</p>');
97+
->appendChild(phutil_tag(
98+
'p',
99+
array(),
100+
pht('There are no facts that can be plotted yet.')));
100101
}
101102

102103
$form = id(new AphrontFormView())

src/applications/herald/controller/HeraldTranscriptController.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,10 @@ public function processRequest() {
3535
$notice = id(new AphrontErrorView())
3636
->setSeverity(AphrontErrorView::SEVERITY_NOTICE)
3737
->setTitle('Old Transcript')
38-
->appendChild(
39-
'<p>Details of this transcript have been garbage collected.</p>');
38+
->appendChild(phutil_tag(
39+
'p',
40+
array(),
41+
'Details of this transcript have been garbage collected.'));
4042
$nav->appendChild($notice);
4143
} else {
4244
$filter = $this->getFilterPHIDs();

src/applications/metamta/controller/PhabricatorMetaMTASendController.php

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -67,12 +67,16 @@ public function processRequest() {
6767
$warning = new AphrontErrorView();
6868
$warning->setTitle('Email is Disabled');
6969
$warning->setSeverity(AphrontErrorView::SEVERITY_WARNING);
70-
$warning->appendChild(
71-
'<p>'.pht('This installation of Phabricator is currently set to use '.
72-
'<tt>PhabricatorMailImplementationTestAdapter</tt> to deliver '.
73-
'outbound email. This completely disables outbound email! All '.
74-
'outbound email will be thrown in a deep, dark hole until you '.
75-
'configure a real adapter.').'</p>');
70+
$warning->appendChild(phutil_tag(
71+
'p',
72+
array(),
73+
pht(
74+
'This installation of Phabricator is currently set to use %s to '.
75+
'deliver outbound email. This completely disables outbound email! '.
76+
'All outbound email will be thrown in a deep, dark hole until you '.
77+
'configure a real adapter.',
78+
phutil_tag('tt', array(), 'PhabricatorMailImplementationTestAdapter'))
79+
));
7680
}
7781

7882
$phdlink_href = PhabricatorEnv::getDoclink(

src/applications/notification/controller/PhabricatorNotificationStatusController.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,14 @@ public function processRequest() {
2424
} catch (Exception $ex) {
2525
$status = new AphrontErrorView();
2626
$status->setTitle("Notification Server Issue");
27-
$status->appendChild(
27+
$status->appendChild(hsprintf(
2828
'Unable to determine server status. This probably means the server '.
2929
'is not in great shape. The specific issue encountered was:'.
3030
'<br />'.
3131
'<br />'.
32-
'<strong>'.phutil_escape_html(get_class($ex)).'</strong> '.
33-
nl2br(phutil_escape_html($ex->getMessage())));
32+
'<strong>%s</strong> %s',
33+
get_class($ex),
34+
phutil_escape_html_newlines($ex->getMessage())));
3435
}
3536

3637
return $this->buildStandardPageResponse(

0 commit comments

Comments
 (0)