diff --git a/model/Request.php b/model/Request.php index b695b2d4e..6af23877c 100644 --- a/model/Request.php +++ b/model/Request.php @@ -208,6 +208,11 @@ public function getLangUrl($newlang=null) if ($newlang !== null) { $langurl = preg_replace("#^(.*/)?{$this->lang}/#", "$1{$newlang}/", $langurl); } + if (str_contains($langurl, '?')) { + $urlparts = explode('?', $langurl); + $langurl = $urlparts[0] . '?' . urlencode($urlparts[1]); + $langurl = str_replace("%3D", "=", $langurl); + } // make sure that the resulting URL isn't interpreted as an absolute URL $langurl = str_replace(":", "", $langurl); return $langurl; diff --git a/tests/RequestTest.php b/tests/RequestTest.php index 10e7654f8..f5183588f 100644 --- a/tests/RequestTest.php +++ b/tests/RequestTest.php @@ -240,4 +240,15 @@ public function testGetLangUrlSanitizeSpecialChars() { $this->assertEquals("http//example.com", $langurl); } + /** + * @covers Request::getLangUrl + */ + public function testGetEncodedUrld() { + $this->request->setServerConstant('SCRIPT_NAME', '/Skosmos/index.php'); + $this->request->setServerConstant('REQUEST_URI', '/Skosmos/afo/fi/page/?uri=http://www.yso.fi/onto/yso/p1669'); + $this->request->setLang('en'); + $langurl = $this->request->getLangUrl(); + $this->assertEquals("afo/fi/page/?uri=http%3A%2F%2Fwww.yso.fi%2Fonto%2Fyso%2Fp1669", $langurl); + } + }