laravel.com
. Let me know if you have any questions.
\ No newline at end of file
diff --git a/tests/Unit/Services/ContentProvidersTest.php b/tests/Unit/Services/ContentProvidersTest.php
index 25709fe0a..9fc7f463d 100644
--- a/tests/Unit/Services/ContentProvidersTest.php
+++ b/tests/Unit/Services/ContentProvidersTest.php
@@ -200,6 +200,29 @@
],
]);
+test('malformed links are correctly handled by content parser', function (string $content) {
+ $provider = new App\Services\ParsableContentProviders\LinkProviderParsable();
+ expect($provider->parse($content))->toMatchSnapshot();
+})->with([
+ 'http://example..com',
+ 'htt://example.com',
+ 'protocol://example.com',
+ 'http//example.com',
+ 'http://exa_mple.com',
+ 'http://example',
+ 'http://.example.com',
+ 'http://example=com',
+ 'www.example.com',
+ 'http:/example.com',
+ 'http:///example.com',
+ 'http://example.com?this<>=that',
+ 'http://example.com?this=that#this<>=that',
+ 'http://[2001:0db8:85a3:0000:0000:8a2e:0370:7334]',
+ 'http://[2001:0db8:85a3:0000:0000:8a2e:0370:7334]:8080',
+ 'http://example.com:abcd',
+ 'http://example.com/👍',
+]);
+
test('only http or https urls are converted to links', function (string $content, string $parsed) {
$provider = new App\Services\ParsableContentProviders\LinkProviderParsable();
diff --git a/tests/Unit/Services/MetaDataTest.php b/tests/Unit/Services/MetaDataTest.php
index 716280a9c..26f4a80ee 100644
--- a/tests/Unit/Services/MetaDataTest.php
+++ b/tests/Unit/Services/MetaDataTest.php
@@ -3,8 +3,11 @@
declare(strict_types=1);
use App\Services\MetaData;
+use GuzzleHttp\Exception\TransferException;
use GuzzleHttp\Promise\RejectedPromise;
+use GuzzleHttp\Psr7\Exception\MalformedUriException;
use Illuminate\Http\Client\ConnectionException;
+use Illuminate\Http\Client\HttpClientException;
use Illuminate\Http\UploadedFile;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\Http;
@@ -261,3 +264,21 @@
expect(round(MetaData::CARD_WIDTH / MetaData::CARD_HEIGHT, 2))
->toBe(round(16 / 9, 2));
});
+
+it('handles all exceptions', function (Exception $exception) {
+ $url = 'https://laravel.com';
+
+ Http::fake([
+ $url => fn ($request) => new RejectedPromise($exception),
+ ]);
+
+ $service = new MetaData($url);
+ $data = $service->fetch();
+
+ expect($data->isEmpty())->toBeTrue();
+})->with([
+ new ConnectionException('Connection error'),
+ new MalformedUriException('Malformed URI'),
+ new HttpClientException('Not Found'),
+ new TransferException('Transfer error'),
+]);