Skip to content

Commit 4cbeed5

Browse files
committed
Amend Wordpress
1 parent eddfd4f commit 4cbeed5

2 files changed

Lines changed: 6 additions & 2 deletions

File tree

src/DDTrace/Integrations/WordPress/WordPressIntegrationLoader.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -742,7 +742,7 @@ function_exists('is_404') && is_404() === false) {
742742
// (?:([^/]+)-)? absent vs present) get distinct cache entries.
743743
$wpParticipation = null;
744744
if ($urlPath !== null) {
745-
if (@preg_match('#^' . $matchedRule . '#', ltrim($urlPath, '/'), $_wpc)) {
745+
if (@preg_match('#^' . $matchedRule . '#', trim($urlPath, '/'), $_wpc)) {
746746
$_bits = [];
747747
for ($_wi = 1; $_wi < count($_wpc); $_wi++) {
748748
$_bits[] = (isset($_wpc[$_wi]) && $_wpc[$_wi] !== '') ? '1' : '0';

src/DDTrace/Util/RouteNormalizer.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,11 @@ public static function normalizeFromWordPress(string $matchedRule, $urlPath = nu
110110
// that didn't participate are skipped instead of emitting phantom params.
111111
$matchedGroups = null;
112112
if ($urlPath !== null) {
113-
if (@preg_match('#^' . $matchedRule . '#', ltrim($urlPath, '/'), $captures)) {
113+
// Strip both leading and trailing slashes: WordPress $wp->request often includes
114+
// a trailing slash, but many WordPress regex rules end with `$` (no `/?`), so a
115+
// trailing slash causes the match to fail and leaves $matchedGroups null — which
116+
// then treats all optional capture groups as present and produces the wrong shape.
117+
if (@preg_match('#^' . $matchedRule . '#', trim($urlPath, '/'), $captures)) {
114118
$matchedGroups = [];
115119
for ($i = 1; $i < count($captures); $i++) {
116120
if (isset($captures[$i]) && $captures[$i] !== '') {

0 commit comments

Comments
 (0)