diff --git a/src/DDTrace/Util/Normalizer.php b/src/DDTrace/Util/Normalizer.php index 042865a2fa..2c3f67ec4a 100644 --- a/src/DDTrace/Util/Normalizer.php +++ b/src/DDTrace/Util/Normalizer.php @@ -218,13 +218,11 @@ private static function generateFilteredPostFields($postKey, $postVal, array $wh // Match it with the regex to redact if needed $obfuscationRegex = \ini_get('datadog.trace.obfuscation_query_string_regexp'); - if ($obfuscationRegex !== "") { - $obfuscationRegex = '(' . $obfuscationRegex . ')'; - if (preg_match($obfuscationRegex, $postField)) { - return [$postKey => '']; - } else { - return [$postKey => $postVal]; - } + $obfuscationRegex = '(' . $obfuscationRegex . ')'; + if (preg_match($obfuscationRegex, $postField)) { + return [$postKey => '']; + } else { + return [$postKey => $postVal]; } } else { // The postkey is not in the whitelist, and no wildcard set, then always use diff --git a/tests/Unit/Util/Normalizer/UriTest.php b/tests/Unit/Util/Normalizer/UriTest.php index b1014043a7..59e09358e3 100644 --- a/tests/Unit/Util/Normalizer/UriTest.php +++ b/tests/Unit/Util/Normalizer/UriTest.php @@ -13,7 +13,6 @@ protected function ddSetUp() 'DD_TRACE_RESOURCE_URI_MAPPING_INCOMING', 'DD_TRACE_RESOURCE_URI_MAPPING_OUTGOING', 'DD_TRACE_RESOURCE_URI_QUERY_PARAM_ALLOWED', - 'DD_TRACE_OBFUSCATION_QUERY_STRING_REGEXP', ]); parent::ddSetUp(); } @@ -26,7 +25,6 @@ protected function ddTearDown() 'DD_TRACE_RESOURCE_URI_MAPPING_INCOMING', 'DD_TRACE_RESOURCE_URI_MAPPING_OUTGOING', 'DD_TRACE_RESOURCE_URI_QUERY_PARAM_ALLOWED', - 'DD_TRACE_OBFUSCATION_QUERY_STRING_REGEXP', ]); } @@ -74,24 +72,6 @@ public function testWrongOutgoingConfigurationResultsInMissedPathNormalizationBu ); } - public function testMixingFragmentRegexAndPatternMatchingIncoming() - { - $this->putEnvAndReloadConfig(['DD_TRACE_RESOURCE_URI_MAPPING_INCOMING=name/*']); - $this->assertSame( - '/numeric/?/name/?', - \DDTrace\Util\Normalizer::uriNormalizeIncomingPath('/numeric/123/name/some_name') - ); - } - - public function testMixingFragmentRegexAndPatternMatchingOutgoing() - { - $this->putEnvAndReloadConfig(['DD_TRACE_RESOURCE_URI_MAPPING_OUTGOING=name/*']); - $this->assertSame( - '/numeric/?/name/?', - \DDTrace\Util\Normalizer::uriNormalizeOutgoingPath('/numeric/123/name/some_name') - ); - } - /** * @dataProvider defaultPathNormalizationScenarios */ diff --git a/tests/ext/root_span_url_with_query_params_obfuscation_empty.phpt b/tests/ext/root_span_url_with_query_params_obfuscation_empty.phpt new file mode 100644 index 0000000000..34ba57827a --- /dev/null +++ b/tests/ext/root_span_url_with_query_params_obfuscation_empty.phpt @@ -0,0 +1,22 @@ +--TEST-- +Root span with http.url and unobfuscated query string with empty regex +--ENV-- +DD_TRACE_GENERATE_ROOT_SPAN=0 +DD_TRACE_OBFUSCATION_QUERY_STRING_REGEXP='' +HTTPS=off +HTTP_HOST=localhost:9999 +SCRIPT_NAME=/foo.php +REQUEST_URI=/users?application_key=123 +QUERY_STRING=application_key=123 +METHOD=GET +--GET-- +application_key=123 +--FILE-- + +--EXPECT-- +string(48) "https://localhost:9999/users?application_key=123"