Open-source social media scheduler built for AI agents and the teams behind them. Create, schedule and publish posts to every network through MCP or the REST API, or write them yourself in a composer your team will love.
PHP ai-agentsblueskyfacebookinstagramlaravellinkedinmastodonmcpmcp-serveropen-sourcerest-apiself-hostedsocial-mediasocial-media-managementsocial-media-schedulerthreadstiktokvuejsxyoutube
Stop URL facets swallowing trailing punctuation
Paulo Castellano2ff34369e0db
diff --git a/app/Services/Social/BlueskyPublisher.php b/app/Services/Social/BlueskyPublisher.phpindex a47115e1d..b117ac62b 100644--- a/app/Services/Social/BlueskyPublisher.php+++ b/app/Services/Social/BlueskyPublisher.php@@ -180,7 +180,7 @@ class BlueskyPublisher);foreach ($urlMatches[0] as $match) {- $url = $match[0];+ $url = $this->trimTrailingUrlPunctuation($match[0]);$start = $this->getUtf8ByteOffset($text, (int) $match[1]);$end = $start + strlen($url);@@ -299,6 +299,24 @@ class BlueskyPublisherreturn strlen(substr($text, 0, $charOffset));}+ /**+ * Trailing sentence punctuation and an unmatched closing paren are almost+ * never part of a URL (e.g. "see https://x.com)."). Mirrors the official+ * atproto link tokenizer so the link facet doesn't over-extend past the URL.+ */+ private function trimTrailingUrlPunctuation(string $url): string+ {+ if (preg_match('/[.,;:!?]$/', $url)) {+ $url = substr($url, 0, -1);+ }++ if (str_ends_with($url, ')') && ! str_contains($url, '(')) {+ $url = substr($url, 0, -1);+ }++ return $url;+ }+private function buildPostUrl(string $handle, string $postId): string{return "https://bsky.app/profile/{$handle}/post/{$postId}";diff --git a/tests/Feature/Services/Social/BlueskyPublisherTest.php b/tests/Feature/Services/Social/BlueskyPublisherTest.phpindex 8df42b214..400a01171 100644--- a/tests/Feature/Services/Social/BlueskyPublisherTest.php+++ b/tests/Feature/Services/Social/BlueskyPublisherTest.php@@ -101,6 +101,52 @@ test('bluesky publisher parses hashtags as facets', function () {});});+test('bluesky publisher strips trailing punctuation from URL facets', function () {+ $this->post->update(['content' => 'see https://example.com).']);++ Http::fake([+ config('trypost.platforms.bluesky.default_service').'/xrpc/com.atproto.repo.createRecord' => Http::response([+ 'uri' => 'at://did:plc:testuser123/app.bsky.feed.post/3abc123xyz',+ 'cid' => 'bafyreiabc123',+ ], 200),+ ]);++ $this->publisher->publish($this->postPlatform);++ Http::assertSent(function ($request) {+ $link = collect($request['record']['facets'] ?? [])+ ->first(fn ($facet) => $facet['features'][0]['$type'] === 'app.bsky.richtext.facet#link');++ return $link+ && $link['features'][0]['uri'] === 'https://example.com'+ && $link['index']['byteEnd'] === $link['index']['byteStart'] + strlen('https://example.com');+ });+});++test('bluesky publisher computes byte offsets after multibyte characters', function () {+ $this->post->update(['content' => 'Olá 🎉 #café']);++ Http::fake([+ config('trypost.platforms.bluesky.default_service').'/xrpc/com.atproto.repo.createRecord' => Http::response([+ 'uri' => 'at://did:plc:testuser123/app.bsky.feed.post/3abc123xyz',+ 'cid' => 'bafyreiabc123',+ ], 200),+ ]);++ $this->publisher->publish($this->postPlatform);++ Http::assertSent(function ($request) {+ $text = $request['record']['text'];+ $tag = collect($request['record']['facets'] ?? [])+ ->first(fn ($facet) => $facet['features'][0]['$type'] === 'app.bsky.richtext.facet#tag');++ // byteStart must be the UTF-8 byte position of '#café', not its character index.+ return $tag+ && $tag['index']['byteStart'] === strpos($text, '#café')+ && $tag['index']['byteEnd'] === strpos($text, '#café') + strlen('#café');+ });+});+test('bluesky publisher resolves mentions to DIDs as facets', function () {$this->post->update(['content' => 'Shout out to @friend.bsky.social']);