From: Arthur Date: Sun, 8 Nov 2015 12:29:32 +0000 (+0100) Subject: Merge pull request #275 from shaarli/plugin-proposition X-Git-Tag: v0.6.0~3 X-Git-Url: https://git.immae.eu/?a=commitdiff_plain;h=fd006c630b64146edc402b68d8503c716f8a55d6;hp=056107ab4eae0a4867cf8d55de77d31f8868b899;p=github%2Fshaarli%2FShaarli.git Merge pull request #275 from shaarli/plugin-proposition Plugin proposition --- diff --git a/application/Utils.php b/application/Utils.php index 1422961d..120333c5 100755 --- a/application/Utils.php +++ b/application/Utils.php @@ -97,12 +97,12 @@ function checkDateFormat($format, $string) */ function generateLocation($referer, $host, $loopTerms = array()) { - $final_referer = '?'; + $finalReferer = '?'; // No referer if it contains any value in $loopCriteria. foreach ($loopTerms as $value) { if (strpos($referer, $value) !== false) { - return $final_referer; + return $finalReferer; } } @@ -111,11 +111,12 @@ function generateLocation($referer, $host, $loopTerms = array()) $host = substr($host, 0, $pos); } - if (!empty($referer) && strpos(parse_url($referer, PHP_URL_HOST), $host) !== false) { - $final_referer = $referer; + $refererHost = parse_url($referer, PHP_URL_HOST); + if (!empty($referer) && (strpos($refererHost, $host) !== false || startsWith('?', $refererHost))) { + $finalReferer = $referer; } - return $final_referer; + return $finalReferer; } /** diff --git a/index.php b/index.php index ea7bf4d1..7383348e 100755 --- a/index.php +++ b/index.php @@ -1439,10 +1439,14 @@ function renderPage() pubsubhub(); // If we are called from the bookmarklet, we must close the popup: - if (isset($_GET['source']) && ($_GET['source']=='bookmarklet' || $_GET['source']=='firefoxsocialapi')) { echo ''; exit; } - $returnurl = ( !empty($_POST['returnurl']) ? escape($_POST['returnurl']) : '?' ); - $returnurl .= '#'.smallHash($_POST['lf_linkdate']); // Scroll to the link which has been edited. + if (isset($_GET['source']) && ($_GET['source']=='bookmarklet' || $_GET['source']=='firefoxsocialapi')) { + echo ''; + exit; + } + + $returnurl = !empty($_POST['returnurl']) ? escape($_POST['returnurl']): '?'; $location = generateLocation($returnurl, $_SERVER['HTTP_HOST'], array('addlink', 'post', 'edit_link')); + $location .= '#'.smallHash($_POST['lf_linkdate']); // Scroll to the link which has been edited. header('Location: '. $location); // After saving the link, redirect to the page the user was on. exit; } diff --git a/tests/UtilsTest.php b/tests/UtilsTest.php index 7f218ad5..311d4bfb 100755 --- a/tests/UtilsTest.php +++ b/tests/UtilsTest.php @@ -118,6 +118,8 @@ class UtilsTest extends PHPUnit_Framework_TestCase $this->assertEquals($ref, generateLocation($ref, 'localhost')); $ref = 'http://localhost:8080/?test'; $this->assertEquals($ref, generateLocation($ref, 'localhost:8080')); + $ref = '?localreferer#hash'; + $this->assertEquals($ref, generateLocation($ref, 'localhost:8080')); } /**