Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: do not partial match url params extraction #22281

Open
wants to merge 9 commits into
base: 5.x-dev
Choose a base branch
from
2 changes: 1 addition & 1 deletion plugins/CustomDimensions/Dimension/Extraction.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ private function formatPattern()

$pattern = $this->pattern;
if ($this->dimension === 'urlparam') {
$pattern = '\?.*' . $pattern . '=([^&]*)';
Lazyuki marked this conversation as resolved.
Show resolved Hide resolved
$pattern = '\?(?:.*&)?' . $pattern . '=([^&]*)';
}

$regex = '/' . str_replace('/', '\/', $pattern) . '/';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
$request = $this->buildRequest();
$value = $extraction->extract($request);

$this->assertSame('fooBarBaz', $value);

Check failure on line 44 in plugins/CustomDimensions/tests/Integration/Dimension/ExtractionTest.php

View workflow job for this annotation

GitHub Actions / PHP (IntegrationTestsPlugins, 7.2, Mysql, PDO_MYSQL)

Failed asserting that two strings are identical.

Check failure on line 44 in plugins/CustomDimensions/tests/Integration/Dimension/ExtractionTest.php

View workflow job for this annotation

GitHub Actions / PHP (IntegrationTestsPlugins, 8.2, Mariadb, PDO_MYSQL)

Failed asserting that two strings are identical.

Check failure on line 44 in plugins/CustomDimensions/tests/Integration/Dimension/ExtractionTest.php

View workflow job for this annotation

GitHub Actions / PHP (IntegrationTestsPlugins, 8.3, Mysql, MYSQLI)

Failed asserting that two strings are identical.
}

public function testNonCapturingGroupWithinCaptureGroup()
Expand All @@ -51,7 +51,7 @@
$request = $this->buildRequest();
$value = $extraction->extract($request);

$this->assertSame('fooBarBaz', $value);

Check failure on line 54 in plugins/CustomDimensions/tests/Integration/Dimension/ExtractionTest.php

View workflow job for this annotation

GitHub Actions / PHP (IntegrationTestsPlugins, 7.2, Mysql, PDO_MYSQL)

Failed asserting that two strings are identical.

Check failure on line 54 in plugins/CustomDimensions/tests/Integration/Dimension/ExtractionTest.php

View workflow job for this annotation

GitHub Actions / PHP (IntegrationTestsPlugins, 8.2, Mariadb, PDO_MYSQL)

Failed asserting that two strings are identical.

Check failure on line 54 in plugins/CustomDimensions/tests/Integration/Dimension/ExtractionTest.php

View workflow job for this annotation

GitHub Actions / PHP (IntegrationTestsPlugins, 8.3, Mysql, MYSQLI)

Failed asserting that two strings are identical.
}

public function testMultipleNonCapturingGroups()
Expand All @@ -61,7 +61,7 @@
$request = $this->buildRequest();
$value = $extraction->extract($request);

$this->assertSame('fooBarBaz', $value);

Check failure on line 64 in plugins/CustomDimensions/tests/Integration/Dimension/ExtractionTest.php

View workflow job for this annotation

GitHub Actions / PHP (IntegrationTestsPlugins, 7.2, Mysql, PDO_MYSQL)

Failed asserting that two strings are identical.

Check failure on line 64 in plugins/CustomDimensions/tests/Integration/Dimension/ExtractionTest.php

View workflow job for this annotation

GitHub Actions / PHP (IntegrationTestsPlugins, 8.2, Mariadb, PDO_MYSQL)

Failed asserting that two strings are identical.

Check failure on line 64 in plugins/CustomDimensions/tests/Integration/Dimension/ExtractionTest.php

View workflow job for this annotation

GitHub Actions / PHP (IntegrationTestsPlugins, 8.3, Mysql, MYSQLI)

Failed asserting that two strings are identical.
}

public function testToArray()
Expand Down Expand Up @@ -116,12 +116,19 @@
{
$request = $this->buildRequest();

$value = $this->buildExtraction('urlparam', 'idsite')->extract($request);
$this->assertSame('54', $value);

$value = $this->buildExtraction('urlparam', 'module')->extract($request);
$this->assertSame('CoreHome', $value);

// Should not pick up "test2" from "secondaction" url param
$value = $this->buildExtraction('urlparam', 'action')->extract($request);
$this->assertSame('test', $value);

$value = $this->buildExtraction('urlparam', 'secondaction')->extract($request);
$this->assertSame('test2', $value);

$value = $this->buildExtraction('urlparam', 'notExist')->extract($request);
$this->assertNull($value);
}
Expand Down Expand Up @@ -205,7 +212,7 @@
$request = $this->buildRequest();

$value = $this->buildExtraction('url', '(.+)')->extract($request);
$this->assertSame('http://www.example.com/test/index.php?idsite=54&module=CoreHome&action=test&camelCase=fooBarBaz', $value);

Check failure on line 215 in plugins/CustomDimensions/tests/Integration/Dimension/ExtractionTest.php

View workflow job for this annotation

GitHub Actions / PHP (IntegrationTestsPlugins, 7.2, Mysql, PDO_MYSQL)

Failed asserting that two strings are identical.

Check failure on line 215 in plugins/CustomDimensions/tests/Integration/Dimension/ExtractionTest.php

View workflow job for this annotation

GitHub Actions / PHP (IntegrationTestsPlugins, 8.2, Mariadb, PDO_MYSQL)

Failed asserting that two strings are identical.

Check failure on line 215 in plugins/CustomDimensions/tests/Integration/Dimension/ExtractionTest.php

View workflow job for this annotation

GitHub Actions / PHP (IntegrationTestsPlugins, 8.3, Mysql, MYSQLI)

Failed asserting that two strings are identical.
}

public function testCheckShouldFailWhenInvalidDimensionGiven()
Expand Down Expand Up @@ -260,7 +267,7 @@

private function buildRequest()
{
$url = 'http://www.example.com/test/index.php?idsite=54&module=CoreHome&action=test&camelCase=fooBarBaz';
$url = 'http://www.example.com/test/index.php?idsite=54&module=CoreHome&action=test&camelCase=fooBarBaz&secondaction=test2';
$referrer = 'http://www.example.com/referrer';
$actionName = 'My Test Title';

Expand Down
Loading