Skip to content

Commit

Permalink
fix: handle relative URL properly
Browse files Browse the repository at this point in the history
A relative URL may be handed over from EXT:matomo_integration.
If this happens, the scheme from the base URL will be prepended now.
  • Loading branch information
brotkrueml committed Dec 2, 2024
1 parent a24ebcb commit 5c79c0a
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 1 deletion.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Fixed
- Using configuration from EXT:matomo_integration with relative URLs throws error

## [3.1.1] - 2024-09-23

### Fixed
Expand Down
4 changes: 4 additions & 0 deletions Classes/Configuration/ConfigurationFinder.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ public static function buildConfigurations(string $configPath, bool $isMatomoInt
$idSite = (string) ($siteConfiguration['matomoWidgetsIdSite'] ?? 0);
}
$url = self::resolveEnvironmentVariable($url);
if (\str_starts_with($url, '//')) {
// We have a relative URL: prepend the scheme from the base URL of the site configuration
$url = \parse_url((string) $siteConfiguration['base'], \PHP_URL_SCHEME) . ':' . $url;
}
$idSite = (int) self::resolveEnvironmentVariable($idSite);
if ($url === '') {
continue;
Expand Down
6 changes: 6 additions & 0 deletions Documentation/Changelog/Index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ and this project adheres to `Semantic Versioning <https://semver.org/spec/v2.0.0
`Unreleased <https://github.com/brotkrueml/typo3-matomo-widgets/compare/v3.1.1...HEAD>`_
--------------------------------------------------------------------------------------------

Fixed
^^^^^


* Using configuration from EXT:matomo_integration with relative URLs throws error

`3.1.1 <https://github.com/brotkrueml/typo3-matomo-widgets/compare/v3.1.0...v3.1.1>`_ - 2024-09-23
------------------------------------------------------------------------------------------------------

Expand Down
16 changes: 16 additions & 0 deletions Tests/Unit/Configuration/ConfigurationFinderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,22 @@ public function siteConfigurationAndAdditionalConfigurationAreBothTakenIntoAccou
self::assertTrue($configurationArray[1]->isWidgetActive('actionsPerDay'));
}

#[Test]
public function siteConfigurationWithRelativeUrlFromMatomoIntegrationUsesSchemeFromBase(): void
{
$this->createSiteConfiguration('some_site', [
'base' => 'https://example.com/',
'matomoWidgetsConsiderMatomoIntegration' => true,
'matomoIntegrationSiteId' => 1,
'matomoIntegrationUrl' => '//matomo.example.com/',
]);

$configurations = ConfigurationFinder::buildConfigurations(self::$configPath, true);
$actualConfiguration = $configurations->getIterator()->current();

self::assertSame('https://matomo.example.com/', $actualConfiguration->url);
}

private function createSiteConfiguration(string $identifier, array $configuration): void
{
$path = self::$configPath . '/sites/' . $identifier;
Expand Down
2 changes: 1 addition & 1 deletion phpstan.baseline.neon
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
parameters:
ignoreErrors:
-
message: "#^Cognitive complexity for \"Brotkrueml\\\\MatomoWidgets\\\\Configuration\\\\ConfigurationFinder\\:\\:buildConfigurations\\(\\)\" is 13, keep it under 8$#"
message: "#^Cognitive complexity for \"Brotkrueml\\\\MatomoWidgets\\\\Configuration\\\\ConfigurationFinder\\:\\:buildConfigurations\\(\\)\" is 14, keep it under 8$#"
count: 1
path: Classes/Configuration/ConfigurationFinder.php

Expand Down

0 comments on commit 5c79c0a

Please sign in to comment.