Skip to content

Commit a3ff546

Browse files
authored
ref(spotlight): normalize spotlight URL to not end with /stream (#1984)
1 parent 1fbcf15 commit a3ff546

File tree

2 files changed

+66
-1
lines changed

2 files changed

+66
-1
lines changed

src/Options.php

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1408,6 +1408,7 @@ private function configureOptions(OptionsResolver $resolver): void
14081408
return array_map([$this, 'normalizeAbsolutePath'], $value);
14091409
});
14101410

1411+
$resolver->setNormalizer('spotlight_url', \Closure::fromCallable([$this, 'normalizeSpotlightUrl']));
14111412
$resolver->setNormalizer('spotlight', \Closure::fromCallable([$this, 'normalizeBooleanOrUrl']));
14121413

14131414
$resolver->setNormalizer('in_app_exclude', function (SymfonyOptions $options, array $value) {
@@ -1445,12 +1446,24 @@ private function normalizeBooleanOrUrl(SymfonyOptions $options, ?string $boolean
14451446
}
14461447

14471448
if (filter_var($booleanOrUrl, \FILTER_VALIDATE_URL)) {
1448-
return $booleanOrUrl;
1449+
return $this->normalizeSpotlightUrl($options, $booleanOrUrl);
14491450
}
14501451

14511452
return filter_var($booleanOrUrl, \FILTER_VALIDATE_BOOLEAN);
14521453
}
14531454

1455+
/**
1456+
* Normalizes the spotlight URL by removing the `/stream` at the end if present.
1457+
*/
1458+
private function normalizeSpotlightUrl(SymfonyOptions $options, string $url): string
1459+
{
1460+
if (substr_compare($url, '/stream', -7, 7) === 0) {
1461+
return substr($url, 0, -7);
1462+
}
1463+
1464+
return $url;
1465+
}
1466+
14541467
/**
14551468
* Normalizes the DSN option by parsing the host, public and secret keys and
14561469
* an optional path.

tests/OptionsTest.php

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -751,4 +751,56 @@ public static function enableTracingDataProvider(): array
751751
[true, null, true],
752752
];
753753
}
754+
755+
/**
756+
* @dataProvider spotlightUrlNormalizationDataProvider
757+
*/
758+
public function testSpotlightUrlNormalization(array $data, string $expected): void
759+
{
760+
$options = new Options($data);
761+
$this->assertSame($expected, $options->getSpotlightUrl());
762+
}
763+
764+
public static function spotlightUrlNormalizationDataProvider(): \Generator
765+
{
766+
yield [['spotlight_url' => 'http://localhost:8969'], 'http://localhost:8969'];
767+
yield [['spotlight_url' => 'http://localhost:8969/stream'], 'http://localhost:8969'];
768+
yield [['spotlight_url' => 'http://localhost:8969/foo'], 'http://localhost:8969/foo'];
769+
yield [['spotlight_url' => 'http://localhost:8969/foo/stream'], 'http://localhost:8969/foo'];
770+
yield [['spotlight_url' => 'http://localhost:8969/stream/foo'], 'http://localhost:8969/stream/foo'];
771+
yield [['spotlight' => 'http://localhost:8969'], 'http://localhost:8969'];
772+
yield [['spotlight' => 'http://localhost:8969/stream'], 'http://localhost:8969'];
773+
yield [['spotlight' => 'http://localhost:8969/foo'], 'http://localhost:8969/foo'];
774+
yield [['spotlight' => 'http://localhost:8969/foo/stream'], 'http://localhost:8969/foo'];
775+
yield [['spotlight' => 'http://localhost:8969/stream/foo'], 'http://localhost:8969/stream/foo'];
776+
}
777+
778+
/**
779+
* @dataProvider setSpotlightUrlNormalizationDataProvider
780+
*/
781+
public function testSetSpotlightUrlNormalization(string $url, string $expected): void
782+
{
783+
$options = new Options();
784+
$options->setSpotlightUrl($url);
785+
$this->assertSame($expected, $options->getSpotlightUrl());
786+
}
787+
788+
/**
789+
* @dataProvider setSpotlightUrlNormalizationDataProvider
790+
*/
791+
public function testEnableSpotlightNormalization(string $url, string $expected): void
792+
{
793+
$options = new Options();
794+
$options->enableSpotlight($url);
795+
$this->assertSame($expected, $options->getSpotlightUrl());
796+
}
797+
798+
public static function setSpotlightUrlNormalizationDataProvider(): \Generator
799+
{
800+
yield ['http://localhost:8969', 'http://localhost:8969'];
801+
yield ['http://localhost:8969/stream', 'http://localhost:8969'];
802+
yield ['http://localhost:8969/foo', 'http://localhost:8969/foo'];
803+
yield ['http://localhost:8969/foo/stream', 'http://localhost:8969/foo'];
804+
yield ['http://localhost:8969/stream/foo', 'http://localhost:8969/stream/foo'];
805+
}
754806
}

0 commit comments

Comments
 (0)