diff --git a/app/Services/EmbedProcessorService.php b/app/Services/EmbedProcessorService.php index 650bb65..0b69ee8 100644 --- a/app/Services/EmbedProcessorService.php +++ b/app/Services/EmbedProcessorService.php @@ -2,14 +2,16 @@ namespace App\Services; -use Illuminate\Support\Facades\Http; -use Illuminate\Support\Facades\Cache; -use Illuminate\Support\Facades\Log; - class EmbedProcessorService { /** - * Process HTML content and convert embed blocks to renderable format + * Process HTML content and convert embed blocks to renderable format. + * + * Every provider is handled with markup only. The provider scripts that + * PostContentText.vue loads (platform.twitter.com/widgets.js, + * instagram.com/embed.js, embed.reddit.com/widgets.js) turn the markup + * below into the real embed on the client — the same path the previous + * oEmbed fallback already relied on whenever a request failed. */ public static function processContent(string $content): string { @@ -36,18 +38,10 @@ private static function processTwitterEmbeds(string $content): string if (preg_match('/status\/(\d+)/', $url, $idMatch)) { $tweetId = $idMatch[1]; - // Try to get oEmbed data from Twitter API (cached) - $embedHtml = self::getTwitterOEmbed($url); - - if ($embedHtml) { - return '
' . - 'Ver tweet' . - '' . + return '
'. + 'Ver tweet'. + ''. '
' . - 'Ver no Instagram' . - '' . + return '
'. + 'Ver no Instagram'. + ''. '
' . - 'Ver no Reddit' . - '' . + return '
'. + 'Ver no Reddit'. + ''. '
Texto entre os embeds.
' + .wpEmbedBlock('youtube', 'https://youtu.be/abc123') + .wpEmbedBlock('instagram', 'https://www.instagram.com/reel/XyZ/') + .wpEmbedBlock('reddit', 'https://www.reddit.com/r/a/comments/b/c/'); + + $html = EmbedProcessorService::processContent($content); + + expect($html) + ->toContain('embed-twitter') + ->toContain('embed-youtube') + ->toContain('embed-instagram') + ->toContain('embed-reddit') + ->toContain('Texto entre os embeds.'); +}); + +it('escapes the url it interpolates into attributes', function () { + // No "<" here on purpose: the pattern stops at it, so this is the shape + // that actually reaches htmlspecialchars(). + $html = EmbedProcessorService::processContent( + wpEmbedBlock('reddit', 'https://www.reddit.com/r/a"onmouseover="alert(1)') + ); + + expect($html) + ->toContain('embed-reddit') + ->toContain('"onmouseover="') + ->not->toContain('"onmouseover="alert(1)'); +}); + +it('leaves content without embeds untouched', function () { + $content = 'Um post comum.