Skip to content
Extraits de code Groupes Projets
Valider ac3b87b6 rédigé par mattpiwik's avatar mattpiwik
Parcourir les fichiers

Fixes #3187 Handle java style matrix URLs

Fixes #3201 GET Parameter with square brackets can now be excluded properly

Thanks catchin for the patches!!
Please consider contributing further patches if you can :)

git-svn-id: http://dev.piwik.org/svn/trunk@6659 59fd770c-687e-43c8-a1e3-f5a4ff64c105
parent ce0c3dfb
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
......@@ -138,11 +138,47 @@ class Piwik_Tracker_Action implements Piwik_Tracker_Action_Interface
$this->actionUrl = $url;
}
/**
* Converts Matrix URL format
* from http://example.org/thing;paramA=1;paramB=6542
* to http://example.org/thing?paramA=1&paramB=6542
*
* @param string $url
*/
static public function convertMatrixUrl($originalUrl)
{
$posFirstSemiColon = strpos($originalUrl,";");
if($posFirstSemiColon === false)
{
return $originalUrl;
}
$posQuestionMark = strpos($originalUrl,"?");
$replace = ($posQuestionMark === false);
if ($posQuestionMark > $posFirstSemiColon)
{
$originalUrl = substr_replace($originalUrl,";",$posQuestionMark,1);
$replace = true;
}
if($replace)
{
$originalUrl = substr_replace($originalUrl,"?",strpos($originalUrl,";"),1);
$originalUrl = str_replace(";","&",$originalUrl);
}
return $originalUrl;
}
static public function normalizeUrl($url)
{
$url = Piwik_Common::unsanitizeInputValue($url);
$url = self::cleanupString($url);
$url = self::convertMatrixUrl($url);
return $url;
}
static public function excludeQueryParametersFromUrl($originalUrl, $idSite)
{
$website = Piwik_Common::getCacheWebsiteAttributes( $idSite );
$originalUrl = Piwik_Common::unsanitizeInputValue($originalUrl);
$originalUrl = self::cleanupString($originalUrl);
$originalUrl = self::normalizeUrl($originalUrl);
$parsedUrl = @parse_url($originalUrl);
if(empty($parsedUrl['query']))
{
......@@ -170,6 +206,9 @@ class Piwik_Tracker_Action implements Piwik_Tracker_Action_Interface
$separator = '&';
foreach($queryParameters as $name => $value)
{
// decode encoded square brackets
$name = str_replace(array('%5B','%5D'),array('[',']'),$name);
if(!in_array(strtolower($name), $parametersToExclude))
{
if (is_array($value))
......
......@@ -1458,9 +1458,11 @@ class Piwik_Tracker_Visit_Referer
$refererUrl = '';
}
$currentUrl = Piwik_Tracker_Action::normalizeUrl($currentUrl);
$this->refererUrl = $refererUrl;
$this->refererUrlParse = @parse_url($this->refererUrl);
$this->currentUrlParse = @parse_url(Piwik_Common::unsanitizeInputValue($currentUrl));
$this->currentUrlParse = @parse_url($currentUrl);
$this->typeRefererAnalyzed = Piwik_Common::REFERER_TYPE_DIRECT_ENTRY;
$this->nameRefererAnalyzed = '';
$this->keywordRefererAnalyzed = '';
......
......@@ -53,14 +53,22 @@ class Test_Piwik_TrackerAction extends Test_Database
'http://a.com/index?p1=v1&P2=v2&p3=v3',
// testing with array []
'http://a.com/index?p1=v1&p2[]=v2a&p2[]=v2b&p2[]=v2c&p3=v3&p4=v4',
'http://a.com/index?p1=v1&p2[]=v;2a&p2[]=v2b&p2[]=v2c&p3=v3&p4=v4',
// testing with missing value
'http://a.com/index?p1=v1&p2=&p3=v3&p4',
'http://a.com/index?p1&p2=v2&p3=v3&p4',
// testing with extra &&
'http://a.com/index?p1=v1&&p2=v2&p3=v3&p4=v4&&',
'http://a.com/index?p1=v1&&p2=v;2&p3=v%3b3&p4=v4&&',
// encoded entities
'http://a.com/index?p1=v1&p2%5B%5D=v2&p3=v3&p4=v4',
'http://a.com/index?var%5Bvalue%5D%5Bdate%5D=01.01.2012',
// matrix parameters
'http://a.com/index;jsessionid=value;p1=v1;p2=v2',
'http://a.com/index;jsessionid=value?p1=v1&p2=v2',
);
return $urls;
......@@ -78,7 +86,7 @@ class Test_Piwik_TrackerAction extends Test_Database
'http://a.com/index?p1=v1',
'http://a.com/index?p1=v1',
'http://a.com/index?p1=v1&P2=v2&p3=v3',
'http://a.com/index?p1=v1&p2[]=v2a&p2[]=v2b&p2[]=v2c&p3=v3&p4=v4',
'http://a.com/index?p1=v1&p2[]=v;2a&p2[]=v2b&p2[]=v2c&p3=v3&p4=v4',
// normalize orphaned p4
'http://a.com/index?p1=v1&p2=&p3=v3&p4',
......@@ -87,7 +95,15 @@ class Test_Piwik_TrackerAction extends Test_Database
'http://a.com/index?p1&p2=v2&p3=v3&p4',
// the extra & are automatically cleaned up
'http://a.com/index?p1=v1&p2=v2&p3=v3&p4=v4',
'http://a.com/index?p1=v1&p2=v;2&p3=v%3b3&p4=v4',
// encoded entities
'http://a.com/index?p1=v1&p2[]=v2&p3=v3&p4=v4',
'http://a.com/index?var[value][date]=01.01.2012',
// matrix parameters
'http://a.com/index?p1=v1&p2=v2',
'http://a.com/index?p1=v1&p2=v2',
);
$this->setUpRootAccess();
$idsite = Piwik_SitesManager_API::getInstance()->addSite("site1",array('http://example.org'),$ecommerce=0, $excludedIps = '', $excludedQueryParameters);
......@@ -114,7 +130,11 @@ class Test_Piwik_TrackerAction extends Test_Database
'http://a.com/index?p1=v1&p3=v3',
'http://a.com/index?p1=v1&p3=v3',
'http://a.com/index?p1&p3=v3',
'http://a.com/index?p1=v1&p3=v3',
'http://a.com/index?p1=v1&p3=v%3b3',
'http://a.com/index?p1=v1&p3=v3',
'http://a.com/index?var[value][date]=01.01.2012',
'http://a.com/index?p1=v1',
'http://a.com/index?p1=v1',
);
$this->setUpRootAccess();
$idsite = Piwik_SitesManager_API::getInstance()->addSite("site1",array('http://example.org'),$ecommerce=0, $excludedIps = '', $excludedQueryParameters);
......@@ -133,7 +153,7 @@ class Test_Piwik_TrackerAction extends Test_Database
function test_excludeQueryParameters_siteAndGlobalExcluded()
{
// testing also that query parameters are case insensitive
$excludedQueryParameters = 'P2';
$excludedQueryParameters = 'P2,var[value][date]';
$excludedGlobalParameters = 'blabla, P4';
$expectedUrls = array(
'http:////wrongurl',
......@@ -144,8 +164,13 @@ class Test_Piwik_TrackerAction extends Test_Database
'http://a.com/index?p1=v1&p3=v3',
'http://a.com/index?p1=v1&p3=v3',
'http://a.com/index?p1&p3=v3',
'http://a.com/index?p1=v1&p3=v%3b3',
'http://a.com/index?p1=v1&p3=v3',
'http://a.com/index',
'http://a.com/index?p1=v1',
'http://a.com/index?p1=v1',
);
$this->setUpRootAccess();
$idsite = Piwik_SitesManager_API::getInstance()->addSite("site1",array('http://example.org'),$ecommerce=0, $excludedIps = '', $excludedQueryParameters);
Piwik_SitesManager_API::getInstance()->setGlobalExcludedQueryParameters($excludedGlobalParameters);
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Veuillez vous inscrire ou vous pour commenter