From 23cd74d28167de2cf9b67a020ebe6df80aab32c4 Mon Sep 17 00:00:00 2001 From: nobody Date: Tue, 23 Feb 2021 15:06:59 -0800 Subject: [PATCH 1/4] Friendica-style bbcode img tags with alt text create bad attachment links --- Zotlabs/Lib/Activity.php | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/Zotlabs/Lib/Activity.php b/Zotlabs/Lib/Activity.php index 9fe2e4eba..9c095ec5a 100644 --- a/Zotlabs/Lib/Activity.php +++ b/Zotlabs/Lib/Activity.php @@ -989,7 +989,11 @@ class Activity { if ($token && $has_images) { for ($n = 0; $n < count($images); $n ++) { $match = $images[$n]; - if (strpos($match[2],z_root() . '/photo/') !== false) { + if (strpos($match[1],'=http') === 0 && strpos($match[1],'/photo/' !== false)) { + $i['body'] = str_replace($match[1],$match[1] . '?token=' . $token, $i['body']); + $images[$n][2] = substr($match[1],1) . '?token=' . $token; + } + elseif (strpos($match[2],z_root() . '/photo/') !== false) { $i['body'] = str_replace($match[2],$match[2] . '?token=' . $token, $i['body']); $images[$n][2] = $match[2] . '?token=' . $token; } @@ -1053,8 +1057,14 @@ class Activity { if ($activitypub && $has_images && $ret['type'] === 'Note') { $img = []; foreach ($images as $match) { - $img[] = [ 'type' => 'Image', 'url' => $match[2] ]; - } + // handle Friendica-style img links with [img=$url]$alttext[/img] + if (strpos($match,'=http') === 0) { + $img[] = [ 'type' => 'Image', 'url' => $match[1] ]; + } + else { + $img[] = [ 'type' => 'Image', 'url' => $match[2] ]; + } + if (! $ret['attachment']) { $ret['attachment'] = []; } From 0afb443758e2de0cd4e5466d942ed7538c254dbd Mon Sep 17 00:00:00 2001 From: nobody Date: Tue, 23 Feb 2021 15:09:46 -0800 Subject: [PATCH 2/4] off by one --- Zotlabs/Lib/Activity.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Zotlabs/Lib/Activity.php b/Zotlabs/Lib/Activity.php index 9c095ec5a..bd31e6878 100644 --- a/Zotlabs/Lib/Activity.php +++ b/Zotlabs/Lib/Activity.php @@ -1059,7 +1059,7 @@ class Activity { foreach ($images as $match) { // handle Friendica-style img links with [img=$url]$alttext[/img] if (strpos($match,'=http') === 0) { - $img[] = [ 'type' => 'Image', 'url' => $match[1] ]; + $img[] = [ 'type' => 'Image', 'url' => substr($match[1],1) ]; } else { $img[] = [ 'type' => 'Image', 'url' => $match[2] ]; From 414c2be024ac1e804924b1280cab0dcddcff7736 Mon Sep 17 00:00:00 2001 From: nobody Date: Tue, 23 Feb 2021 15:22:30 -0800 Subject: [PATCH 3/4] don't try to purify an array --- Zotlabs/Lib/Activity.php | 25 +++++++++++++------------ include/items.php | 4 +++- 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/Zotlabs/Lib/Activity.php b/Zotlabs/Lib/Activity.php index bd31e6878..605b28f5c 100644 --- a/Zotlabs/Lib/Activity.php +++ b/Zotlabs/Lib/Activity.php @@ -1057,19 +1057,20 @@ class Activity { if ($activitypub && $has_images && $ret['type'] === 'Note') { $img = []; foreach ($images as $match) { - // handle Friendica-style img links with [img=$url]$alttext[/img] - if (strpos($match,'=http') === 0) { - $img[] = [ 'type' => 'Image', 'url' => substr($match[1],1) ]; - } - else { - $img[] = [ 'type' => 'Image', 'url' => $match[2] ]; - } + // handle Friendica-style img links with [img=$url]$alttext[/img] + if (strpos($match,'=http') === 0) { + $img[] = [ 'type' => 'Image', 'url' => substr($match[1],1) ]; + } + else { + $img[] = [ 'type' => 'Image', 'url' => $match[2] ]; + } - if (! $ret['attachment']) { - $ret['attachment'] = []; - } - $ret['attachment'] = array_merge($img,$ret['attachment']); - } + if (! $ret['attachment']) { + $ret['attachment'] = []; + } + $ret['attachment'] = array_merge($img,$ret['attachment']); + } + } // addressing madness diff --git a/include/items.php b/include/items.php index c1241b9da..1802752c2 100644 --- a/include/items.php +++ b/include/items.php @@ -1367,7 +1367,9 @@ function purify_imported_object($obj) { $ret = null; if (is_array($obj)) { foreach ( $obj as $k => $v ) { - $ret[$k] = purify_html($v); + if (is_string($v)) { + $ret[$k] = purify_html($v); + } } } elseif (is_string($obj)) { From 4ae24c8a9a94bb3bff26ef636dd7a81315d42ac8 Mon Sep 17 00:00:00 2001 From: nobody Date: Tue, 23 Feb 2021 15:36:39 -0800 Subject: [PATCH 4/4] looks like some content fields found in the wild are actually arrays --- include/items.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/include/items.php b/include/items.php index 1802752c2..b2d22e3ee 100644 --- a/include/items.php +++ b/include/items.php @@ -1367,7 +1367,10 @@ function purify_imported_object($obj) { $ret = null; if (is_array($obj)) { foreach ( $obj as $k => $v ) { - if (is_string($v)) { + if (is_array($v)) { + $ret[$k] = purify_imported_object($v); + } + elseif (is_string($v)) { $ret[$k] = purify_html($v); } }