Skip to content

Commit 1767b80

Browse files
author
epriestley
committedJan 31, 2019
Replace manual query string construction with "phutil_build_http_querystring()"
Summary: Now that we have a nice function for this, use it to simplify some code. Test Plan: Ran through the Duo enroll workflow to make sure signing still works. Reviewers: amckinley Reviewed By: amckinley Differential Revision: https://secure.phabricator.com/D20053
1 parent a24e6de commit 1767b80

File tree

4 files changed

+9
-12
lines changed

4 files changed

+9
-12
lines changed
 

‎src/aphront/configuration/AphrontApplicationConfiguration.php

+6-2
Original file line numberDiff line numberDiff line change
@@ -772,6 +772,11 @@ private static function readHTTPPOSTData() {
772772
$multipart_parser->continueParse($raw_input);
773773
$parts = $multipart_parser->endParse();
774774

775+
// We're building and then parsing a query string so that requests
776+
// with arrays (like "x[]=apple&x[]=banana") work correctly. This also
777+
// means we can't use "phutil_build_http_querystring()", since it
778+
// can't build a query string with duplicate names.
779+
775780
$query_string = array();
776781
foreach ($parts as $part) {
777782
if (!$part->isVariable()) {
@@ -780,8 +785,7 @@ private static function readHTTPPOSTData() {
780785

781786
$name = $part->getName();
782787
$value = $part->getVariableValue();
783-
784-
$query_string[] = urlencode($name).'='.urlencode($value);
788+
$query_string[] = rawurlencode($name).'='.rawurlencode($value);
785789
}
786790
$query_string = implode('&', $query_string);
787791
$post = $parser->parseQueryString($query_string);

‎src/applications/auth/factor/PhabricatorDuoAuthFactor.php

+1-4
Original file line numberDiff line numberDiff line change
@@ -504,10 +504,7 @@ protected function newIssuedChallenges(
504504
$push_info = array(
505505
pht('Domain') => $this->getInstallDisplayName(),
506506
);
507-
foreach ($push_info as $k => $v) {
508-
$push_info[$k] = rawurlencode($k).'='.rawurlencode($v);
509-
}
510-
$push_info = implode('&', $push_info);
507+
$push_info = phutil_build_http_querystring($push_info);
511508

512509
$parameters = array(
513510
'username' => $duo_user,

‎src/applications/auth/future/PhabricatorDuoFuture.php

+1-5
Original file line numberDiff line numberDiff line change
@@ -91,11 +91,7 @@ protected function getProxiedFuture() {
9191
$http_method = $this->getHTTPMethod();
9292

9393
ksort($data);
94-
$data_parts = array();
95-
foreach ($data as $key => $value) {
96-
$data_parts[] = rawurlencode($key).'='.rawurlencode($value);
97-
}
98-
$data_parts = implode('&', $data_parts);
94+
$data_parts = phutil_build_http_querystring($data);
9995

10096
$corpus = array(
10197
$date,

‎src/applications/diffusion/controller/DiffusionServeController.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -528,7 +528,7 @@ private function serveGitRequest(
528528
unset($query_data[$key]);
529529
}
530530
}
531-
$query_string = http_build_query($query_data, '', '&');
531+
$query_string = phutil_build_http_querystring($query_data);
532532

533533
// We're about to wipe out PATH with the rest of the environment, so
534534
// resolve the binary first.

0 commit comments

Comments
 (0)
Failed to load comments.