From b2bc5f3c58276e13c91a41d8fe89230f32fce089 Mon Sep 17 00:00:00 2001 From: Arthur Schiwon Date: Sat, 30 Jul 2016 01:46:30 +0200 Subject: [PATCH 1/2] Fix overwrite of bookmarks when importing links without URL --- controller/lib/bookmarks.php | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/controller/lib/bookmarks.php b/controller/lib/bookmarks.php index f328393997..2bb391b522 100644 --- a/controller/lib/bookmarks.php +++ b/controller/lib/bookmarks.php @@ -428,7 +428,10 @@ public static function editBookmark($userid, IDb $db, $id, $url, $title, $tags = */ public static function addBookmark($userid, IDb $db, $url, $title, $tags = array(), $description = '', $is_public = false) { $public = $is_public ? 1 : 0; - $url_without_prefix = substr($url, strpos($url, "://") + 3); // Removes everything from the url before the "://" pattern (included) + $url_without_prefix = trim(substr($url, strpos($url, "://") + 3)); // Removes everything from the url before the "://" pattern (included) + if($url_without_prefix === '') { + throw new \InvalidArgumentException('Bookmark URL is missing'); + } $enc_url_noprefix = htmlspecialchars_decode($url_without_prefix); $enc_url = htmlspecialchars_decode($url); // Change lastmodified date if the record if already exists @@ -522,8 +525,12 @@ public static function importFile($user, IDb $db, $file) { $dom->loadHTMLFile($file); $links = $dom->getElementsByTagName('a'); + $l = \OC::$server->getL10NFactory()->get('bookmarks'); + $errors = []; + // Reintroduce transaction here!? foreach ($links as $link) { + /* @var \DOMElement $link */ $title = $link->nodeValue; $ref = $link->getAttribute("href"); $tag_str = ''; @@ -534,11 +541,15 @@ public static function importFile($user, IDb $db, $file) { $desc_str = ''; if ($link->hasAttribute("description")) $desc_str = $link->getAttribute("description"); - - self::addBookmark($user, $db, $ref, $title, $tags, $desc_str); + try { + self::addBookmark($user, $db, $ref, $title, $tags, $desc_str); + } catch (\InvalidArgumentException $e) { + \OC::$server->getLogger()->logException($e, ['app' => 'bookmarks']); + $errors[] = $l->t('Failed to import one bookmark, because: ') . $e->getMessage(); + } } - return array(); + return $errors; } /** From 930e1e1ce68eaa0da03eef1e55db03b080f0dbe7 Mon Sep 17 00:00:00 2001 From: Arthur Schiwon Date: Sat, 6 Aug 2016 01:10:10 +0200 Subject: [PATCH 2/2] increase title size to 4096, and cut title and description before writing to DB --- appinfo/database.xml | 2 +- appinfo/info.xml | 2 +- controller/lib/bookmarks.php | 4 ++++ 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/appinfo/database.xml b/appinfo/database.xml index 923e50c60b..004cd33e3c 100644 --- a/appinfo/database.xml +++ b/appinfo/database.xml @@ -27,7 +27,7 @@ text true - 140 + 4096 user_id diff --git a/appinfo/info.xml b/appinfo/info.xml index 8a21edbd9e..31d7675662 100644 --- a/appinfo/info.xml +++ b/appinfo/info.xml @@ -10,5 +10,5 @@ 168710 - 0.6.1 + 0.6.2 diff --git a/controller/lib/bookmarks.php b/controller/lib/bookmarks.php index 2bb391b522..f433c8d35b 100644 --- a/controller/lib/bookmarks.php +++ b/controller/lib/bookmarks.php @@ -434,6 +434,10 @@ public static function addBookmark($userid, IDb $db, $url, $title, $tags = array } $enc_url_noprefix = htmlspecialchars_decode($url_without_prefix); $enc_url = htmlspecialchars_decode($url); + + $title = mb_substr($title, 0, 4096); + $description = mb_substr($description, 0, 4096); + // Change lastmodified date if the record if already exists $sql = "SELECT * from `*PREFIX*bookmarks` WHERE `url` like ? AND `user_id` = ?"; $query = $db->prepareQuery($sql, 1);