mirror of
https://we.phorge.it/source/phorge.git
synced 2024-12-23 22:10:55 +01:00
Replace "getQueryParams()" callsites in Phabricator
Summary: See D20136. This method is sort of inherently bad because it is destructive for some inputs (`x=1&x=2`) and had "PHP-flavored" behavior for other inputs (`x[]=1&x[]=2`). Move to explicit `...AsMap` and `...AsPairList` methods. Test Plan: Bit of an adventure, see inlines in a minute. Reviewers: amckinley Reviewed By: amckinley Differential Revision: https://secure.phabricator.com/D20141
This commit is contained in:
parent
187356fea5
commit
1fd69f788c
6 changed files with 42 additions and 13 deletions
|
@ -438,12 +438,13 @@ abstract class PhabricatorAuthProvider extends Phobject {
|
|||
|
||||
$uri = $attributes['uri'];
|
||||
$uri = new PhutilURI($uri);
|
||||
$params = $uri->getQueryParams();
|
||||
$params = $uri->getQueryParamsAsPairList();
|
||||
$uri->setQueryParams(array());
|
||||
|
||||
$content = array($button);
|
||||
|
||||
foreach ($params as $key => $value) {
|
||||
foreach ($params as $pair) {
|
||||
list($key, $value) = $pair;
|
||||
$content[] = phutil_tag(
|
||||
'input',
|
||||
array(
|
||||
|
|
|
@ -1098,7 +1098,8 @@ final class DifferentialRevisionViewController
|
|||
// D123.vs123.id123.whitespaceignore-all.diff
|
||||
// lame but nice to include these options
|
||||
$file_name = ltrim($request_uri->getPath(), '/').'.';
|
||||
foreach ($request_uri->getQueryParams() as $key => $value) {
|
||||
foreach ($request_uri->getQueryParamsAsPairList() as $pair) {
|
||||
list($key, $value) = $pair;
|
||||
if ($key == 'download') {
|
||||
continue;
|
||||
}
|
||||
|
|
|
@ -358,7 +358,7 @@ final class DifferentialChangesetListView extends AphrontView {
|
|||
|
||||
if ($this->standaloneURI) {
|
||||
$uri = new PhutilURI($this->standaloneURI);
|
||||
$uri->setQueryParams($uri->getQueryParams() + $qparams);
|
||||
$uri = $this->appendDefaultQueryParams($uri, $qparams);
|
||||
$meta['standaloneURI'] = (string)$uri;
|
||||
}
|
||||
|
||||
|
@ -381,7 +381,7 @@ final class DifferentialChangesetListView extends AphrontView {
|
|||
if ($this->leftRawFileURI) {
|
||||
if ($change != DifferentialChangeType::TYPE_ADD) {
|
||||
$uri = new PhutilURI($this->leftRawFileURI);
|
||||
$uri->setQueryParams($uri->getQueryParams() + $qparams);
|
||||
$uri = $this->appendDefaultQueryParams($uri, $qparams);
|
||||
$meta['leftURI'] = (string)$uri;
|
||||
}
|
||||
}
|
||||
|
@ -390,7 +390,7 @@ final class DifferentialChangesetListView extends AphrontView {
|
|||
if ($change != DifferentialChangeType::TYPE_DELETE &&
|
||||
$change != DifferentialChangeType::TYPE_MULTICOPY) {
|
||||
$uri = new PhutilURI($this->rightRawFileURI);
|
||||
$uri->setQueryParams($uri->getQueryParams() + $qparams);
|
||||
$uri = $this->appendDefaultQueryParams($uri, $qparams);
|
||||
$meta['rightURI'] = (string)$uri;
|
||||
}
|
||||
}
|
||||
|
@ -421,4 +421,23 @@ final class DifferentialChangesetListView extends AphrontView {
|
|||
|
||||
}
|
||||
|
||||
private function appendDefaultQueryParams(PhutilURI $uri, array $params) {
|
||||
// Add these default query parameters to the query string if they do not
|
||||
// already exist.
|
||||
|
||||
$have = array();
|
||||
foreach ($uri->getQueryParamsAsPairList() as $pair) {
|
||||
list($key, $value) = $pair;
|
||||
$have[$key] = true;
|
||||
}
|
||||
|
||||
foreach ($params as $key => $value) {
|
||||
if (!isset($have[$key])) {
|
||||
$uri->appendQueryParam($key, $value);
|
||||
}
|
||||
}
|
||||
|
||||
return $uri;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -709,8 +709,6 @@ final class DiffusionBrowseController extends DiffusionController {
|
|||
'path' => $path,
|
||||
));
|
||||
|
||||
$before_uri->setQueryParams($request->getRequestURI()->getQueryParams());
|
||||
$before_uri = $before_uri->alter('before', null);
|
||||
$before_uri = $before_uri->alter('renamed', $renamed);
|
||||
$before_uri = $before_uri->alter('follow', $follow);
|
||||
|
||||
|
|
|
@ -256,8 +256,8 @@ final class PhabricatorOAuthServer extends Phobject {
|
|||
|
||||
// Any query parameters present in the first URI must be exactly present
|
||||
// in the second URI.
|
||||
$need_params = $primary_uri->getQueryParams();
|
||||
$have_params = $secondary_uri->getQueryParams();
|
||||
$need_params = $primary_uri->getQueryParamsAsMap();
|
||||
$have_params = $secondary_uri->getQueryParamsAsMap();
|
||||
|
||||
foreach ($need_params as $key => $value) {
|
||||
if (!array_key_exists($key, $have_params)) {
|
||||
|
|
|
@ -18,12 +18,22 @@ final class PhabricatorYoutubeRemarkupRule extends PhutilRemarkupRule {
|
|||
return $text;
|
||||
}
|
||||
|
||||
$params = $uri->getQueryParams();
|
||||
$v_param = idx($params, 'v');
|
||||
if (!strlen($v_param)) {
|
||||
$v_params = array();
|
||||
|
||||
$params = $uri->getQueryParamsAsPairList();
|
||||
foreach ($params as $pair) {
|
||||
list($k, $v) = $pair;
|
||||
if ($k === 'v') {
|
||||
$v_params[] = $v;
|
||||
}
|
||||
}
|
||||
|
||||
if (count($v_params) !== 1) {
|
||||
return $text;
|
||||
}
|
||||
|
||||
$v_param = head($v_params);
|
||||
|
||||
$text_mode = $this->getEngine()->isTextMode();
|
||||
$mail_mode = $this->getEngine()->isHTMLMailMode();
|
||||
|
||||
|
|
Loading…
Reference in a new issue