1
0
mirror of https://github.com/owncloud/bookmarks.git synced 2025-02-21 18:54:32 +01:00

backport of #240

use parse_url to verify dn, because filter_var has issues with special chars

Add test on adding bookmark with URL containing umlaut

Does not relate to this issue (different code path, not covered by tests
yet), but still it is a good addition.
This commit is contained in:
Arthur Schiwon 2016-04-20 21:51:30 +02:00
parent 6828edb806
commit 45fab84796
No known key found for this signature in database
GPG Key ID: 7424F1874854DF23
2 changed files with 9 additions and 4 deletions

View File

@ -69,7 +69,8 @@ class BookmarkController extends ApiController {
public function newBookmark($url = "", $item = array(), $from_own = 0, $title = "", $is_public = false, $description = "") {
// Check if it is a valid URL
if (filter_var($url, FILTER_VALIDATE_URL) === FALSE) {
$urlData = parse_url($url);
if ($urlData === false || !isset($urlData['scheme']) || !isset($urlData['host'])) {
return new JSONResponse(array('status' => 'error'), Http::STATUS_BAD_REQUEST);
}
@ -112,7 +113,8 @@ class BookmarkController extends ApiController {
public function editBookmark($id = null, $url = "", $item = array(), $title = "", $is_public = false, $record_id = null, $description = "") {
// Check if it is a valid URL
if (filter_var($url, FILTER_VALIDATE_URL) === FALSE) {
$urlData = parse_url($url);
if ($urlData === false || !isset($urlData['scheme']) || !isset($urlData['host'])) {
return new JSONResponse(array(), Http::STATUS_BAD_REQUEST);
}
@ -169,7 +171,8 @@ class BookmarkController extends ApiController {
public function clickBookmark($url = "") {
// Check if it is a valid URL
if (filter_var($url, FILTER_VALIDATE_URL) === FALSE) {
$urlData = parse_url($url);
if ($urlData === false || !isset($urlData['scheme']) || !isset($urlData['host'])) {
return new JSONResponse(array(), Http::STATUS_BAD_REQUEST);
}

View File

@ -17,8 +17,10 @@ class Test_LibBookmarks_Bookmarks extends PHPUnit_Framework_TestCase {
function testAddBookmark() {
$this->cleanDB();
$this->assertCount(0, Bookmarks::findBookmarks($this->userid, $this->db, 0, 'id', array(), true, -1));
Bookmarks::addBookmark($this->userid, $this->db, 'http://owncloud.org', 'Owncloud project', array('oc', 'cloud'), 'An Awesome project');
Bookmarks::addBookmark($this->userid, $this->db, 'http://owncloud.org', 'owncloud project', array('oc', 'cloud'), 'An Awesome project');
$this->assertCount(1, Bookmarks::findBookmarks($this->userid, $this->db, 0, 'id', array(), true, -1));
Bookmarks::addBookmark($this->userid, $this->db, 'http://de.wikipedia.org/Ü', 'Das Ü', array('encyclopedia', 'lang'), 'A terrific letter');
$this->assertCount(2, Bookmarks::findBookmarks($this->userid, $this->db, 0, 'id', array(), true, -1));
}
function testFindBookmarks() {