Skip to content

Commit d817dfa

Browse files
author
vrana
committed
Convert some phutil_escape_html() to hsprintf()
Summary: Found by `sgrep_php -e '"...".phutil_escape_html(...)'`. Test Plan: / /D1 /uiexample/ /countdown/1/ /herald/transcript/1/all/ Reviewers: epriestley Reviewed By: epriestley CC: aran, Korvin Maniphest Tasks: T2432 Differential Revision: https://secure.phabricator.com/D4869
1 parent 138da5a commit d817dfa

File tree

46 files changed

+299
-325
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+299
-325
lines changed

src/aphront/configuration/AphrontDefaultApplicationConfiguration.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -182,10 +182,9 @@ public function handleException(Exception $ex) {
182182
return $login_controller->processRequest();
183183
}
184184

185-
$content =
186-
'<div class="aphront-policy-exception">'.
187-
phutil_escape_html($ex->getMessage()).
188-
'</div>';
185+
$content = hsprintf(
186+
'<div class="aphront-policy-exception">%s</div>',
187+
$ex->getMessage());
189188

190189
$dialog = new AphrontDialogView();
191190
$dialog

src/applications/auth/controller/PhabricatorLoginValidateController.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,9 @@ public function processRequest() {
4343

4444
$list = array();
4545
foreach ($failures as $failure) {
46-
$list[] = '<li>'.phutil_escape_html($failure).'</li>';
46+
$list[] = phutil_tag('li', array(), $failure);
4747
}
48-
$list = '<ul>'.implode("\n", $list).'</ul>';
48+
$list = phutil_tag('ul', array(), $list);
4949

5050
$view = new AphrontRequestFailureView();
5151
$view->setHeader(pht('Login Failed'));

src/applications/auth/controller/PhabricatorMustVerifyEmailController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public function processRequest() {
4545
'<p>'.
4646
pht('You must verify your email address to login. You should have a new '.
4747
'email message from Phabricator with verification instructions in your '.
48-
'inbox (<strong>%s</strong>).', phutil_escape_html($email_address)).
48+
'inbox (%s).', phutil_tag('strong', array(), $email_address)).
4949
'</p>');
5050
$error_view->appendChild(
5151
'<p>'.

src/applications/auth/controller/PhabricatorOAuthLoginController.php

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -69,14 +69,16 @@ public function processRequest() {
6969
$dialog = new AphrontDialogView();
7070
$dialog->setUser($current_user);
7171
$dialog->setTitle(pht('Already Linked to Another Account'));
72-
$dialog->appendChild('<p>'.
72+
$dialog->appendChild(phutil_tag(
73+
'p',
74+
array(),
7375
pht(
7476
'The %s account you just authorized is already linked to '.
7577
'another Phabricator account. Before you can associate your %s '.
7678
'account with this Phabriactor account, you must unlink it from '.
77-
'the Phabricator account it is currently linked to.</p>',
78-
phutil_escape_html($provider_name),
79-
phutil_escape_html($provider_name))).'</p>';
79+
'the Phabricator account it is currently linked to.',
80+
$provider_name,
81+
$provider_name)));
8082
$dialog->addCancelButton($provider->getSettingsPanelURI());
8183

8284
return id(new AphrontDialogResponse())->setDialog($dialog);
@@ -97,13 +99,15 @@ public function processRequest() {
9799
$dialog->setUser($current_user);
98100
$dialog->setTitle(
99101
pht('Already Linked to an Account From This Provider'));
100-
$dialog->appendChild('<p>'.
102+
$dialog->appendChild(phutil_tag(
103+
'p',
104+
array(),
101105
pht(
102106
'The account you are logged in with is already linked to a %s '.
103107
'account. Before you can link it to a different %s account, you '.
104-
'must unlink the old account.</p>',
105-
phutil_escape_html($provider_name),
106-
phutil_escape_html($provider_name))).'</p>';
108+
'must unlink the old account.',
109+
$provider_name,
110+
$provider_name)));
107111
$dialog->addCancelButton($provider->getSettingsPanelURI());
108112
return id(new AphrontDialogResponse())->setDialog($dialog);
109113
}
@@ -170,13 +174,15 @@ public function processRequest() {
170174
$dialog = new AphrontDialogView();
171175
$dialog->setUser($current_user);
172176
$dialog->setTitle(pht('Already Linked to Another Account'));
173-
$dialog->appendChild('<p>'.
177+
$dialog->appendChild(phutil_tag(
178+
'p',
179+
array(),
174180
pht(
175181
'The %s account you just authorized has an email address which '.
176182
'is already in use by another Phabricator account. To link the '.
177183
'accounts, log in to your Phabricator account and then go to '.
178184
'Settings.',
179-
phutil_escape_html($provider_name))).'</p>';
185+
$provider_name)));
180186

181187
$user = id(new PhabricatorUser())
182188
->loadOneWhere('phid = %s', $known_email->getUserPHID());
@@ -189,10 +195,12 @@ public function processRequest() {
189195
$providers[] = PhabricatorOAuthProvider::newProvider($provider)
190196
->getProviderName();
191197
}
192-
$dialog->appendChild(
198+
$dialog->appendChild(phutil_tag(
199+
'p',
200+
array(),
193201
pht(
194-
'<p>The account is associated with: %s.</p>',
195-
implode(', ', phutil_escape_html($providers))));
202+
'The account is associated with: %s.',
203+
implode(', ', $providers))));
196204
}
197205

198206
$dialog->addCancelButton('/login/');
@@ -205,13 +213,15 @@ public function processRequest() {
205213
$dialog = new AphrontDialogView();
206214
$dialog->setUser($current_user);
207215
$dialog->setTitle(pht('No Account Registration with %s', $provider_name));
208-
$dialog->appendChild('<p>'.
216+
$dialog->appendChild(phutil_tag(
217+
'p',
218+
array(),
209219
pht(
210220
'You can not register a new account using %s; you can only use '.
211221
'your %s account to log into an existing Phabricator account which '.
212222
'you have registered through other means.',
213-
phutil_escape_html($provider_name),
214-
phutil_escape_html($provider_name))).'</p>';
223+
$provider_name,
224+
$provider_name)));
215225
$dialog->addCancelButton('/login/');
216226

217227
return id(new AphrontDialogResponse())->setDialog($dialog);

src/applications/countdown/controller/PhabricatorCountdownDeleteController.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@ public function processRequest() {
3333
$dialog = new AphrontDialogView();
3434
$dialog->setUser($request->getUser());
3535
$dialog->setTitle('Really delete this countdown?');
36-
$dialog->appendChild(
37-
'<p>Are you sure you want to delete the countdown "'.
38-
phutil_escape_html($timer->getTitle()).'"?</p>');
36+
$dialog->appendChild(hsprintf(
37+
'<p>Are you sure you want to delete the countdown "%s"?</p>',
38+
$timer->getTitle()));
3939
$dialog->addSubmitButton('Delete');
4040
$dialog->addCancelButton('/countdown/');
4141
$dialog->setSubmitURI($request->getPath());

src/applications/countdown/controller/PhabricatorCountdownViewController.php

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,9 @@ public function processRequest() {
3232
$chrome_visible ? pht('Disable Chrome') : pht('Enable Chrome'));
3333

3434
$container = celerity_generate_unique_node_id();
35-
$content =
36-
'<div class="phabricator-timer" id="'.$container.'">
37-
<h1 class="phabricator-timer-header">'.
38-
phutil_escape_html($timer->getTitle()).' &middot; '.
39-
phabricator_datetime($timer->getDatePoint(), $user).
40-
'</h1>
35+
$content = hsprintf(
36+
'<div class="phabricator-timer" id="%s">
37+
<h1 class="phabricator-timer-header">%s &middot; %s</h1>
4138
<div class="phabricator-timer-pane">
4239
<table class="phabricator-timer-table">
4340
<tr>
@@ -46,20 +43,19 @@ public function processRequest() {
4643
<th>Minutes</th>
4744
<th>Seconds</th>
4845
</tr>
49-
<tr>'.
50-
javelin_tag('td',
51-
array('sigil' => 'phabricator-timer-days'), '').
52-
javelin_tag('td',
53-
array('sigil' => 'phabricator-timer-hours'), '').
54-
javelin_tag('td',
55-
array('sigil' => 'phabricator-timer-minutes'), '').
56-
javelin_tag('td',
57-
array('sigil' => 'phabricator-timer-seconds'), '').
58-
'</tr>
46+
<tr>%s%s%s%s</tr>
5947
</table>
60-
</div>'.
61-
$chrome_link.
62-
'</div>';
48+
</div>
49+
%s
50+
</div>',
51+
$container,
52+
$timer->getTitle(),
53+
phabricator_datetime($timer->getDatePoint(), $user),
54+
javelin_tag('td', array('sigil' => 'phabricator-timer-days'), ''),
55+
javelin_tag('td', array('sigil' => 'phabricator-timer-hours'), ''),
56+
javelin_tag('td', array('sigil' => 'phabricator-timer-minutes'), ''),
57+
javelin_tag('td', array('sigil' => 'phabricator-timer-seconds'), ''),
58+
$chrome_link);
6359

6460
Javelin::initBehavior('countdown-timer', array(
6561
'timestamp' => $timer->getDatepoint(),

src/applications/daemon/view/PhabricatorDaemonLogEventsView.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public function render() {
6363
phutil_escape_html($event->getLogType()),
6464
phabricator_date($event->getEpoch(), $this->user),
6565
phabricator_time($event->getEpoch(), $this->user),
66-
str_replace("\n", '<br />', phutil_escape_html($message.$more)),
66+
phutil_escape_html_newlines($message.$more),
6767
);
6868

6969
if ($this->combinedLog) {

src/applications/differential/controller/DifferentialCommentSaveController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public function processRequest() {
5656

5757
$dialog->setTitle(pht('Action Has No Effect'));
5858
$dialog->appendChild(
59-
'<p>'.phutil_escape_html($no_effect->getMessage()).'</p>');
59+
phutil_tag('p', array(), $no_effect->getMessage()));
6060

6161
if (strlen($comment) || $has_inlines) {
6262
$dialog->addSubmitButton(pht('Post as Comment'));

src/applications/differential/render/DifferentialChangesetHTMLRenderer.php

Lines changed: 26 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,7 @@ protected function renderChangeTypeHeader($force) {
7070
break;
7171

7272
case DifferentialChangeType::TYPE_MOVE_HERE:
73-
$from =
74-
"<strong>".
75-
phutil_escape_html($changeset->getOldFile()).
76-
"</strong>";
73+
$from = phutil_tag('strong', array(), $changeset->getOldFile());
7774
switch ($file) {
7875
case DifferentialChangeType::FILE_TEXT:
7976
$message = pht('This file was moved from %s.', $from);
@@ -97,10 +94,7 @@ protected function renderChangeTypeHeader($force) {
9794
break;
9895

9996
case DifferentialChangeType::TYPE_COPY_HERE:
100-
$from =
101-
"<strong>".
102-
phutil_escape_html($changeset->getOldFile()).
103-
"</strong>";
97+
$from = phutil_tag('strong', array(), $changeset->getOldFile());
10498
switch ($file) {
10599
case DifferentialChangeType::FILE_TEXT:
106100
$message = pht('This file was copied from %s.', $from);
@@ -124,10 +118,10 @@ protected function renderChangeTypeHeader($force) {
124118
break;
125119

126120
case DifferentialChangeType::TYPE_MOVE_AWAY:
127-
$paths =
128-
"<strong>".
129-
phutil_escape_html(implode(', ', $changeset->getAwayPaths())).
130-
"</strong>";
121+
$paths = phutil_tag(
122+
'strong',
123+
array(),
124+
implode(', ', $changeset->getAwayPaths()));
131125
switch ($file) {
132126
case DifferentialChangeType::FILE_TEXT:
133127
$message = pht('This file was moved to %s.', $paths);
@@ -151,10 +145,10 @@ protected function renderChangeTypeHeader($force) {
151145
break;
152146

153147
case DifferentialChangeType::TYPE_COPY_AWAY:
154-
$paths =
155-
"<strong>".
156-
phutil_escape_html(implode(', ', $changeset->getAwayPaths())).
157-
"</strong>";
148+
$paths = phutil_tag(
149+
'strong',
150+
array(),
151+
implode(', ', $changeset->getAwayPaths()));
158152
switch ($file) {
159153
case DifferentialChangeType::FILE_TEXT:
160154
$message = pht('This file was copied to %s.', $paths);
@@ -178,10 +172,10 @@ protected function renderChangeTypeHeader($force) {
178172
break;
179173

180174
case DifferentialChangeType::TYPE_MULTICOPY:
181-
$paths =
182-
"<strong>".
183-
phutil_escape_html(implode(', ', $changeset->getAwayPaths())).
184-
"</strong>";
175+
$paths = phutil_tag(
176+
'strong',
177+
array(),
178+
implode(', ', $changeset->getAwayPaths()));
185179
switch ($file) {
186180
case DifferentialChangeType::FILE_TEXT:
187181
$message = pht(
@@ -262,23 +256,26 @@ protected function renderPropertyChangeHeader() {
262256
$nval = idx($new, $key);
263257
if ($oval !== $nval) {
264258
if ($oval === null) {
265-
$oval = '<em>null</em>';
259+
$oval = phutil_tag('em', array(), 'null');
266260
} else {
267-
$oval = nl2br(phutil_escape_html($oval));
261+
$oval = phutil_escape_html_newlines($oval);
268262
}
269263

270264
if ($nval === null) {
271-
$nval = '<em>null</em>';
265+
$nval = phutil_tag('em', array(), 'null');
272266
} else {
273-
$nval = nl2br(phutil_escape_html($nval));
267+
$nval = phutil_escape_html_newlines($nval);
274268
}
275269

276-
$rows[] =
270+
$rows[] = hsprintf(
277271
'<tr>'.
278-
'<th>'.phutil_escape_html($key).'</th>'.
279-
'<td class="oval">'.$oval.'</td>'.
280-
'<td class="nval">'.$nval.'</td>'.
281-
'</tr>';
272+
'<th>%s</th>'.
273+
'<td class="oval">%s</td>'.
274+
'<td class="nval">%s</td>'.
275+
'</tr>',
276+
$key,
277+
$oval,
278+
$nval);
282279
}
283280
}
284281

src/applications/differential/view/DifferentialLocalCommitsView.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -54,33 +54,33 @@ public function render() {
5454
} else {
5555
$commit_hash = null;
5656
}
57-
$row[] = '<td>'.phutil_escape_html($commit_hash).'</td>';
57+
$row[] = phutil_tag('td', array(), $commit_hash);
5858

5959
if ($has_tree) {
6060
$tree = idx($commit, 'tree');
6161
$tree = substr($tree, 0, 16);
62-
$row[] = '<td>'.phutil_escape_html($tree).'</td>';
62+
$row[] = phutil_tag('td', array(), $tree);
6363
}
6464

6565
if ($has_local) {
6666
$local_rev = idx($commit, 'local', null);
67-
$row[] = '<td>'.phutil_escape_html($local_rev).'</td>';
67+
$row[] = phutil_tag('td', array(), $local_rev);
6868
}
6969

7070
$parents = idx($commit, 'parents', array());
7171
foreach ($parents as $k => $parent) {
7272
if (is_array($parent)) {
7373
$parent = idx($parent, 'rev');
7474
}
75-
$parents[$k] = phutil_escape_html(substr($parent, 0, 16));
75+
$parents[$k] = substr($parent, 0, 16);
7676
}
77-
$parents = implode('<br />', $parents);
78-
$row[] = '<td>'.$parents.'</td>';
77+
$parents = array_interleave(phutil_tag('br'), $parents);
78+
$row[] = phutil_tag('td', array(), $parents);
7979

8080
$author = nonempty(
8181
idx($commit, 'user'),
8282
idx($commit, 'author'));
83-
$row[] = '<td>'.phutil_escape_html($author).'</td>';
83+
$row[] = phutil_tag('td', array(), $author);
8484

8585
$message = idx($commit, 'message');
8686

@@ -107,9 +107,9 @@ public function render() {
107107
if ($date) {
108108
$date = phabricator_datetime($date, $user);
109109
}
110-
$row[] = '<td>'.$date.'</td>';
110+
$row[] = phutil_tag('td', array(), $date);
111111

112-
$rows[] = '<tr class="'.$class.'">'.implode('', $row).'</tr>';
112+
$rows[] = phutil_tag('tr', array('class' => $class), $row);
113113
}
114114

115115

0 commit comments

Comments
 (0)