Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added url encoding to getLangUrl function #1542

Open
wants to merge 1 commit into
base: skosmos-2
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions model/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
11 changes: 11 additions & 0 deletions tests/RequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

}
Loading