Skip to content

Commit

Permalink
Refs #2135
Browse files Browse the repository at this point in the history
 * NAILED the encoding! wow that was tough for my brain, but finally got around it.

 Some findings:
 _GET is automatically URL decoded
 QUERY_STRING contains raw URL so we'll use this one instead
 I REALLY want to simplify the whole "_GET" variables within Piwik so that all code uses a static method to get input variables. Refs #3931
  • Loading branch information
mattab committed May 11, 2013
1 parent 028342a commit 263892f
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 6 deletions.
15 changes: 13 additions & 2 deletions core/API/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -191,8 +191,9 @@ private function extractModuleAndMethod($parameter)
*/
public static function processRequest($method, $paramOverride = array())
{
// set up request params
$params = $_GET + $_POST;
// QUERY_STRING contains the URL encoded parameters which we're looking for
$GET = self::getRequestParametersGET();
$params = $GET + $_POST;
$params['format'] = 'original';
$params['module'] = 'API';
$params['method'] = $method;
Expand All @@ -202,4 +203,14 @@ public static function processRequest($method, $paramOverride = array())
$request = new Piwik_API_Request($params);
return $request->process();
}

/**
* @return array
*/
public static function getRequestParametersGET()
{
$GET = Piwik_Common::getArrayFromQueryString($_SERVER['QUERY_STRING']);
return $GET;
}

}
5 changes: 4 additions & 1 deletion core/SegmentExpression.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ public function parseSubExpressions()
$parsedSubExpressions = array();
foreach ($this->tree as $id => $leaf) {
$operand = $leaf[self::INDEX_OPERAND];

$operand = urldecode($operand);

$operator = $leaf[self::INDEX_BOOL_OPERATOR];
$pattern = '/^(.+?)(' . self::MATCH_EQUAL . '|'
. self::MATCH_NOT_EQUAL . '|'
Expand All @@ -79,7 +82,7 @@ public function parseSubExpressions()

$leftMember = $matches[1];
$operation = $matches[2];
$valueRightMember = $matches[3];
$valueRightMember = urldecode($matches[3]);
$parsedSubExpressions[] = array(
self::INDEX_BOOL_OPERATOR => $operator,
self::INDEX_OPERAND => array(
Expand Down
4 changes: 1 addition & 3 deletions core/ViewDataTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -586,9 +586,7 @@ protected function getRequestString()
// we need the URL encoded segment parameter, we fetch it from _SERVER['QUERY_STRING'] instead of default URL decoded _GET
$segment = Piwik_Common::getRequestVar('segment', '', 'string');
if (!empty($segment)) {
$requestRaw = Piwik_Common::getArrayFromQueryString($_SERVER['QUERY_STRING']);
$requestRaw['segment'] = str_replace('%3C', '<', $requestRaw['segment']);
$requestRaw['segment'] = str_replace('%3E', '>', $requestRaw['segment']);
$requestRaw = Piwik_API_Request::getRequestParametersGET();
$requestString .= '&segment=' . $requestRaw['segment'];
}
return $requestString;
Expand Down

0 comments on commit 263892f

Please sign in to comment.