[Piwik-svn] r371 - in trunk: misc/testJavascriptTracker modules modules/LogStats tests/modules
svnmaster at piwik.org
svnmaster at piwik.org
Fri Mar 14 21:01:19 CET 2008
Author: matt
Date: 2008-03-14 21:01:17 +0100 (Fri, 14 Mar 2008)
New Revision: 371
Modified:
trunk/misc/testJavascriptTracker/index.php
trunk/modules/Common.php
trunk/modules/LogStats/Action.php
trunk/tests/modules/Common.test.php
Log:
- refs #40 updated test cases, updated function to test if an url looks like an URL in order to support ftp:// news:// etc.
Modified: trunk/misc/testJavascriptTracker/index.php
===================================================================
--- trunk/misc/testJavascriptTracker/index.php 2008-03-13 15:19:07 UTC (rev 370)
+++ trunk/misc/testJavascriptTracker/index.php 2008-03-14 20:01:17 UTC (rev 371)
@@ -2,7 +2,8 @@
require_once '../../modules/Url.php';
$url = Piwik_Url::getCurrentUrlWithoutFileName();
-$urlPiwik = join("/", array_slice(split("/", $url), 0, -3));
+$urlPiwik = join("/", array_slice(split("/", $url), 0, -3));
+
?>
<div>
@@ -11,16 +12,20 @@
<br />
</div>
-<a href="http://www.google.fr"> Site web de google france </a> <br />
-<a href="http://www.yahoo.fr"> Site web de yahoo france </a> <br />
-<a href="http://www.google.com"> Site web de google monde </a> <br />
-<a href="http://maps.google.fr"> Site web de google maps </a> <br />
-<a href="http://piwik.org"> Site web de piwik </a> <br />
-<a href="http://piwik.org/blog"> Site web de piwik </a> <br />
-<br />
-<a href="./test.pdf"> download pdf (rel) </a> <br />
-<a href="./test.jpg"> download jpg (rel) </a> <br />
-<a href="./test.zip"> download zip (rel) </a> <br />
+<a href="http://www.yahoo.fr"> yahoo france website</a> <br />
+<a href="http://www.google.com"> google world website </a> <br />
+<a href="ftp://parcftp.xerox.com"> FTP xerox</a> <br />
+<a href="news://news.eclipse.org"> News::eclipse</a> <br />
+<a href="http://piwik.org"> piwik website </a> <br />
+
+<br />
+<a class="piwik_ignore" href="./THIS_PDF_SHOULD_NOT_BE_COUNTED.pdf"> PDF wthdownload pdf </a> <br />
+<a href="./test.pdf"> download pdf (rel) </a> <br />
+<a href="./dir_test/test.pdf"> download pdf + directory (rel) </a> <br />
+<a href="../testJavascriptTracker/dir_test/test.pdf"> download pdf + parent directory (rel) </a> <br />
+<a href="./test.jpg"> download jpg (rel) </a> <br />
+<a href="./test.zip"> download zip (rel) </a> <br />
+<a href="./test.php?fileToDownload=test.zip"> download strange URL ?file=test.zip</a> <br />
<a href="
<?php echo $url; ?>
test.rar"> download rar (abs) </a> <br />
Modified: trunk/modules/Common.php
===================================================================
--- trunk/modules/Common.php 2008-03-13 15:19:07 UTC (rev 370)
+++ trunk/modules/Common.php 2008-03-14 20:01:17 UTC (rev 371)
@@ -50,9 +50,17 @@
return $result;
}
- static function isUrl( $url )
+ /**
+ * Returns true if the string passed may be a URL.
+ * We don't need a precise test here as the value comes from the website
+ * tracked source code and the URLs may look very strange.
+ *
+ * @param string $url
+ * @return bool
+ */
+ static function isLookLikeUrl( $url )
{
- return ereg('^http[s]?://[A-Za-z0-9\/_.-]', $url);
+ return ereg('^(ftp|news|http|https)?://[A-Za-z0-9\/_.-?&]*', $url);
}
/**
Modified: trunk/modules/LogStats/Action.php
===================================================================
--- trunk/modules/LogStats/Action.php 2008-03-13 15:19:07 UTC (rev 370)
+++ trunk/modules/LogStats/Action.php 2008-03-14 20:01:17 UTC (rev 371)
@@ -163,7 +163,7 @@
$actionCategoryDelimiter = Piwik_LogStats_Config::getInstance()->General['action_category_delimiter'];
// case the name is an URL we dont clean the name the same way
- if(Piwik_Common::isUrl($actionName))
+ if(Piwik_Common::isLookLikeUrl($actionName))
{
$actionName = trim($actionName);
}
Modified: trunk/tests/modules/Common.test.php
===================================================================
--- trunk/tests/modules/Common.test.php 2008-03-13 15:19:07 UTC (rev 370)
+++ trunk/tests/modules/Common.test.php 2008-03-14 20:01:17 UTC (rev 371)
@@ -23,6 +23,37 @@
public function tearDown()
{
}
+
+ function test_isUrl()
+ {
+ $valid = array(
+ 'http://piwik.org',
+ 'http://www.piwik.org',
+ 'https://piwik.org',
+ 'https://piwik.org/dir/dir2/?oeajkgea7aega=&ge=a',
+ 'ftp://www.pi-wik.org',
+ 'news://www.pi-wik.org',
+ );
+
+ foreach($valid as $url)
+ {
+ $this->assertTrue(Piwik_Common::isLookLikeUrl($url), "$url not validated");
+ }
+ }
+ function test_isUrl_notvalid()
+ {
+ $notValid = array(
+ 'it doesnt look like url',
+ '/index?page=test',
+ 'test.html',
+
+ );
+
+ foreach($notValid as $url)
+ {
+ $this->assertTrue(!Piwik_Common::isLookLikeUrl($url), "$url validated");
+ }
+ }
// sanitize an array OK
function test_sanitizeInputValues_array1()
More information about the Piwik-svn
mailing list