From c40390c202016db26621c65713aa3e890b5c4809 Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Sun, 3 Oct 2021 15:22:40 -0400 Subject: [PATCH 1/5] Revert "Explicitly cast Url objects to string" This reverts commit ee5aa2d4327699ae80c281c6aebbeaf6f06be269. --- src/Navigation/Notifications/Depository/Notify.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Navigation/Notifications/Depository/Notify.php b/src/Navigation/Notifications/Depository/Notify.php index 73eff7694d..4c7a1ef33d 100644 --- a/src/Navigation/Notifications/Depository/Notify.php +++ b/src/Navigation/Notifications/Depository/Notify.php @@ -104,11 +104,11 @@ class Notify extends BaseDepository $fields = [ 'type' => $Notify->type, 'name' => $Notify->name, - 'url' => (string)$Notify->url, - 'photo' => (string)$Notify->photo, + 'url' => $Notify->url, + 'photo' => $Notify->photo, 'msg' => $Notify->msg, 'uid' => $Notify->uid, - 'link' => (string)$Notify->link, + 'link' => $Notify->link, 'iid' => $Notify->itemId, 'parent' => $Notify->parent, 'seen' => $Notify->seen, From 24734b05fef936f77b6e9f1b2d36cad49575e1b9 Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Sun, 3 Oct 2021 15:23:35 -0400 Subject: [PATCH 2/5] Cast object parameters to string in Database\Database - This makes string casting in Depository->save unnecessary --- src/Database/Database.php | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/src/Database/Database.php b/src/Database/Database.php index fe137b39be..a654cccc5b 100644 --- a/src/Database/Database.php +++ b/src/Database/Database.php @@ -549,12 +549,14 @@ class Database break; } - foreach ($args as $param => $value) { + foreach (array_keys($args) as $param) { + $data_type = PDO::PARAM_STR; if (is_int($args[$param])) { $data_type = PDO::PARAM_INT; - } else { - $data_type = PDO::PARAM_STR; + } elseif ($args[$param] !== null) { + $args[$param] = (string)$args[$param]; } + $stmt->bindParam($param, $args[$param], $data_type); } @@ -605,13 +607,16 @@ class Database $param_types = ''; $values = []; - foreach ($args as $param => $value) { + foreach (array_keys($args) as $param) { if (is_int($args[$param])) { $param_types .= 'i'; } elseif (is_float($args[$param])) { $param_types .= 'd'; } elseif (is_string($args[$param])) { $param_types .= 's'; + } elseif (is_object($args[$param]) && method_exists($args[$param], '__toString')) { + $param_types .= 's'; + $args[$param] = (string)$args[$param]; } else { $param_types .= 'b'; } @@ -969,7 +974,7 @@ class Database } /** - * Insert a row into a table + * Insert a row into a table. Field value objects will be cast as string. * * @param string|array $table Table name or array [schema => table] * @param array $param parameter array @@ -1244,9 +1249,9 @@ class Database } /** - * Updates rows + * Updates rows in the database. Field value objects will be cast as string. * - * Updates rows in the database. When $old_fields is set to an array, + * When $old_fields is set to an array, * the system will only do an update if the fields in that array changed. * * Attention: @@ -1561,9 +1566,9 @@ class Database } } - return $fields; + return $fields; } - + /** * Returns the error number of the last query * From a4706e9521be2719d96ceeb7800c06371316a684 Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Sun, 3 Oct 2021 19:32:20 -0400 Subject: [PATCH 3/5] Trim XML before emptiness check in Protocol\Feed::import - Address https://github.com/friendica/friendica/issues/10791 --- src/Protocol/Feed.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Protocol/Feed.php b/src/Protocol/Feed.php index d793ac817f..907479776c 100644 --- a/src/Protocol/Feed.php +++ b/src/Protocol/Feed.php @@ -69,6 +69,8 @@ class Feed Logger::info("Import Atom/RSS feed '" . $contact["name"] . "' (Contact " . $contact["id"] . ") for user " . $importer["uid"]); } + $xml = trim($xml); + if (empty($xml)) { Logger::info('XML is empty.'); return []; @@ -83,7 +85,7 @@ class Feed } $doc = new DOMDocument(); - @$doc->loadXML(trim($xml)); + @$doc->loadXML($xml); $xpath = new DOMXPath($doc); $xpath->registerNamespace('atom', ActivityNamespace::ATOM1); $xpath->registerNamespace('dc', "http://purl.org/dc/elements/1.1/"); From 42e77e23acfe9d923b0d7da56e60b54403c53df6 Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Sun, 3 Oct 2021 19:18:00 -0400 Subject: [PATCH 4/5] Add logging to track a Notice messages - Part of https://github.com/friendica/friendica/issues/10755#issuecomment-933040517 --- src/Model/User.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/Model/User.php b/src/Model/User.php index 8f69aa87c8..3178b888e7 100644 --- a/src/Model/User.php +++ b/src/Model/User.php @@ -850,6 +850,10 @@ class User */ public static function getAvatarUrl(array $user, string $size = ''):string { + if (empty($user['nickname'])) { + DI::logger()->warning('Missing user nickname key', ['trace' => System::callstack(20)]); + } + $url = DI::baseUrl() . '/photo/'; switch ($size) { From 297ff765901e5baa55c5a87bb9c5db9450079700 Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Sun, 3 Oct 2021 20:56:45 -0400 Subject: [PATCH 5/5] Relax check on id parameter in /photo - Address https://github.com/friendica/friendica/issues/10756#issuecomment-933020126 - Address https://github.com/friendica/friendica/issues/10755#issuecomment-933020316 --- src/Module/Photo.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Module/Photo.php b/src/Module/Photo.php index ea6af26367..e1a8eef87b 100644 --- a/src/Module/Photo.php +++ b/src/Module/Photo.php @@ -98,7 +98,7 @@ class Photo extends BaseModule } // Please refactor this for the love of everything that's good - if (!empty($parameters['id'])) { + if (isset($parameters['id'])) { $uid = $parameters['id']; }