From f77d33302de49fa5643408079631c6bdabec23b1 Mon Sep 17 00:00:00 2001 From: Muhammad Asad <140322913+Masad791@users.noreply.github.com> Date: Sat, 31 Oct 2026 18:40:30 +0500 Subject: [PATCH] fix(text): allow building the card context without a user Text dispatches RegisterContextEvent on every request, including the public share session sync/save requests. Building the listener for it constructs TextContextProviderFactory, and the container passes null as userId when nobody is logged in, so the string type threw a TypeError and public Markdown previews failed with HTTP 500 while Deck was enabled. Accept a null userId in the factory and the provider, like CardService and PermissionService already do. Fixes #8633 Signed-off-by: Muhammad Asad <140322913+Masad791@users.noreply.github.com> --- lib/Provider/TextContextProvider.php | 2 +- lib/Provider/TextContextProviderFactory.php | 2 +- .../TextContextProviderFactoryTest.php | 39 +++++++++++++++++++ 3 files changed, 41 insertions(+), 2 deletions(-) create mode 100644 tests/unit/Provider/TextContextProviderFactoryTest.php diff --git a/lib/Provider/TextContextProvider.php b/lib/Provider/TextContextProvider.php index 089cdacb3..11f705734 100644 --- a/lib/Provider/TextContextProvider.php +++ b/lib/Provider/TextContextProvider.php @@ -31,7 +31,7 @@ public function __construct( private readonly CardService $cardService, private readonly CardMapper $cardMapper, private readonly PermissionService $permissionService, - private readonly string $userId, + private readonly ?string $userId, private readonly int $cardId, ) { } diff --git a/lib/Provider/TextContextProviderFactory.php b/lib/Provider/TextContextProviderFactory.php index e5223bc53..6f4791fa6 100644 --- a/lib/Provider/TextContextProviderFactory.php +++ b/lib/Provider/TextContextProviderFactory.php @@ -22,7 +22,7 @@ public function __construct( private readonly CardService $cardService, private readonly CardMapper $cardMapper, private readonly PermissionService $permissionService, - private readonly string $userId, + private readonly ?string $userId, ) { } diff --git a/tests/unit/Provider/TextContextProviderFactoryTest.php b/tests/unit/Provider/TextContextProviderFactoryTest.php new file mode 100644 index 000000000..dcb88d139 --- /dev/null +++ b/tests/unit/Provider/TextContextProviderFactoryTest.php @@ -0,0 +1,39 @@ +markTestSkipped('Text app not available'); + } + } + + /** + * Text dispatches its context event on public share requests too, where there is no user + */ + public function testBuildForCardWithoutUser(): void { + $factory = new TextContextProviderFactory( + $this->createMock(SecureRandom::class), + $this->createMock(CardService::class), + $this->createMock(CardMapper::class), + $this->createMock(PermissionService::class), + null, + ); + + $this->assertSame(5, $factory->buildForCard(5)->getId()); + } +}