]> gitweb.fluxo.info Git - lorea/elgg.git/commitdiff
Fixes #2463: Added ^ to beginning of normalize_url regex to prevent matching on urls...
authorewinslow <ewinslow@36083f99-b078-4883-b0ff-0f9b5a30f544>
Thu, 4 Nov 2010 20:08:20 +0000 (20:08 +0000)
committerewinslow <ewinslow@36083f99-b078-4883-b0ff-0f9b5a30f544>
Thu, 4 Nov 2010 20:08:20 +0000 (20:08 +0000)
git-svn-id: http://code.elgg.org/elgg/trunk@7236 36083f99-b078-4883-b0ff-0f9b5a30f544

engine/lib/output.php
engine/tests/api/helpers.php

index 84b012631c1ece05a11f2139b3dd0d821f80b5a9..cac7eeb5bbf8060d7f3bf5e696d8fbef3beb9f9a 100644 (file)
@@ -161,11 +161,11 @@ function elgg_normalize_url($url) {
        }
 
        // 'example.com', 'example.com/subpage'
-       elseif (preg_match("#[^/]*\.[^/]*/?#i", $url)) {
+       elseif (preg_match("#^[^/]*\.#i", $url)) {
                return "http://$url";
        }
 
-       // 'pg/page/handler'
+       // 'pg/page/handler', 'mod/plugin/file.php'
        else {
                return elgg_get_site_url().$url;
        }
index b8c7f048d62e938477525a4fdae678ef834acc0b..8dab74ff8e0a4514f6f5a3267ae4c4c301583e8a 100644 (file)
@@ -64,6 +64,26 @@ class ElggCoreHelpersTest extends ElggCoreUnitTest {
                $this->assertFalse(elgg_instanceof($bad_entity, 'object', 'test_subtype'));
        }
 
+       /**
+        * Test elgg_normalize_url()
+        */
+       public function testElggNormalizeURL() {
+               $conversions = array(
+                       'http://example.com' => 'http://example.com', 
+                       'https://example.com' => 'https://example.com', 
+                       '//example.com' => '//example.com',
+                       'example.com' => 'http://example.com',
+                       'example.com/subpage' => 'http://example.com/subpage',
+                       'pg/page/handler' => elgg_get_site_url().'pg/page/handler',
+                       'mod/plugin/file.php' => elgg_get_site_url().'mod/plugin/file.php',
+               );
+               
+               foreach ($conversions as $input => $output) {
+                       $this->assertIdentical($output, elgg_normalize_url($input));
+               }
+       }
+       
+       
        /**
         * Test elgg_register_js()
         */