Skip to content

Commit 4248174

Browse files
committed
improved url detection in oEmbed using initialurl
1 parent 0f78989 commit 4248174

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/OEmbed.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ class OEmbed
1212
use HttpApiTrait;
1313

1414
private static $providers;
15+
private array $defaults = [];
1516

1617
private static function getProviders(): array
1718
{
@@ -70,6 +71,7 @@ private function detectEndpointFromProviders(): ?UriInterface
7071
$initialUrl = (string) $this->extractor->getRequest()->getUri();
7172

7273
if ($initialUrl !== $url && ($endpoint = $this->detectEndpointFromUrl($initialUrl))) {
74+
$this->defaults['url'] = $initialUrl;
7375
return $endpoint;
7476
}
7577

@@ -139,7 +141,7 @@ private static function extractXML(string $xml): array
139141
$data[$name] = $value;
140142
}
141143

142-
return $data;
144+
return $data ? ($data + $this->defaults) : [];
143145
} catch (Exception $exception) {
144146
return [];
145147
}
@@ -148,7 +150,9 @@ private static function extractXML(string $xml): array
148150
private static function extractJSON(string $json): array
149151
{
150152
try {
151-
return json_decode($json, true) ?: [];
153+
$data = json_decode($json, true);
154+
155+
return $data ? ($data + $this->defaults) : [];
152156
} catch (Exception $exception) {
153157
return [];
154158
}

0 commit comments

Comments
 (0)