Fixed InvalidArgumentException: Accessed unknown getter 'video_url' on XF:Attachment

Affected version
2.2.1

rik

Member
Hi there,

we're getting errors about an unknown getter on the Attachment entity when accessing a thread via Xenforo's API.

Environment​

  • Xenforo 2.2.1
  • PHP 7.4.12
  • MySQL 8.0.22

Observed error​

Code:
InvalidArgumentException: Accessed unknown getter 'video_url' on XF:Attachment[<ID>] src/XF/Mvc/Entity/Entity.php:203

Stack-Trace​

Code:
#0 src/XF/Mvc/Entity/Entity.php(110): XF\Mvc\Entity\Entity->get()
#1 src/XF/BbCode/Renderer/ApiHtml.php(58): XF\Mvc\Entity\Entity->__get()
#2 [internal function]: XF\BbCode\Renderer\ApiHtml->renderTagAttach()
#3 src/XF/BbCode/Renderer/Html.php(307): call_user_func()
#4 src/XF/BbCode/Traverser.php(61): XF\BbCode\Renderer\Html->renderTag()
#5 src/XF/BbCode/Traverser.php(37): XF\BbCode\Traverser->renderSubTree()
#6 src/XF/BbCode/Traverser.php(20): XF\BbCode\Traverser->renderAst()
#7 src/XF/SubContainer/BbCode.php(220): XF\BbCode\Traverser->render()
#8 src/XF/Entity/Post.php(919): XF\SubContainer\BbCode->render()
#9 src/XF/Mvc/Entity/Entity.php(537): XF\Entity\Post->setupApiResultData()
#10 src/XF/Mvc/Entity/AbstractCollection.php(45): XF\Mvc\Entity\Entity->toApiResult()
#11 src/XF/Api/Controller/Thread.php(126): XF\Mvc\Entity\AbstractCollection->toApiResults()
#12 src/XF/Api/Controller/Thread.php(90): XF\Api\Controller\Thread->getPostsInThreadPaginated()
#13 src/XF/Mvc/Dispatcher.php(350): XF\Api\Controller\Thread->actionGetPosts()
#14 src/XF/Api/Mvc/Dispatcher.php(27): XF\Mvc\Dispatcher->dispatchClass()
#15 src/XF/Mvc/Dispatcher.php(113): XF\Api\Mvc\Dispatcher->dispatchFromMatch()
#16 src/XF/Mvc/Dispatcher.php(55): XF\Mvc\Dispatcher->dispatchLoop()
#17 src/XF/App.php(2300): XF\Mvc\Dispatcher->run()
#18 src/XF.php(465): XF\App->run()
#19 index.php(16): XF::runApp()
#20 {main}

Request Data​

Code:
array(4) {
  ["url"] => string(36) "/forum/api/threads/<THREAD_ID>/posts?page=1"
  ["referrer"] => string(60) "https://www.example.org/forum/api/threads/<THREAD_ID>/posts?page=1"
  ["_GET"] => array(1) {
    ["page"] => string(1) "1"
  }
  ["_POST"] => array(0) {
  }
}

Steps to reproduce​

  • create a post with an attached video
  • fetch the post's thread via Xenforo's API (/forum/api/threads/<thread_id>/posts)

Findings​

  • in ApiHtml.php, line 58 the property/getter video_url for the Attachment entity is accessed
  • the getter for that property isn't found, so an exception is thrown (Entity.php:202)
  • if the getter name in ApiHtml:58 is changed to direct_url everything works as expected:

Diff:
diff --git src/XF/BbCode/Renderer/ApiHtml.php src/XF/BbCode/Renderer/ApiHtml.php
index c1ed3ee..13f4914 100644
--- src/XF/BbCode/Renderer/ApiHtml.php
+++ src/XF/BbCode/Renderer/ApiHtml.php
@@ -55,7 +55,7 @@ class ApiHtml extends Html
 
         if ($attachment->is_video && $canView)
         {
-            $videoUrl = \XF::canonicalizeUrl($attachment->video_url);
+            $videoUrl = \XF::canonicalizeUrl($attachment->direct_url);
             return '<video controls><source src="' . htmlspecialchars($videoUrl) . '" /></video>';
         }
         else if ($isFull && $attachment->Data->width)
 

XF Bug Bot

XenForo bug fixer bot
Staff member
Thank you for reporting this issue, it has now been resolved. We are aiming to include any changes that have been made in a future XF release (2.2.2).

Change log:
Prevent an error when fetching a post that contains an embedded video via the API.
There may be a delay before changes are rolled out to the XenForo Community.
 
Top