From 15b5c59935722a3b888c99aea2858cc67633d9e7 Mon Sep 17 00:00:00 2001 From: moander Date: Fri, 22 Oct 2021 12:13:45 +0200 Subject: [PATCH] fix(core): support regex global flag in urlMatches --- packages/opentelemetry-core/src/utils/url.ts | 2 +- packages/opentelemetry-core/test/utils/url.test.ts | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/packages/opentelemetry-core/src/utils/url.ts b/packages/opentelemetry-core/src/utils/url.ts index 9db9725b823..a6122ae7842 100644 --- a/packages/opentelemetry-core/src/utils/url.ts +++ b/packages/opentelemetry-core/src/utils/url.ts @@ -17,7 +17,7 @@ export function urlMatches(url: string, urlToMatch: string | RegExp): boolean { if (typeof urlToMatch === 'string') { return url === urlToMatch; } else { - return urlToMatch.test(url); + return !!url.match(urlToMatch); } } /** diff --git a/packages/opentelemetry-core/test/utils/url.test.ts b/packages/opentelemetry-core/test/utils/url.test.ts index 91ae9b75c53..afc1446962e 100644 --- a/packages/opentelemetry-core/test/utils/url.test.ts +++ b/packages/opentelemetry-core/test/utils/url.test.ts @@ -71,5 +71,17 @@ describe('Core - Utils - url', () => { ); }); }); + describe('when regex has global flag', () => { + it('should return true', () => { + const ignoredUrls = [/myaddr/g]; + for (let i = 0; i < 2; i++) { + assert.strictEqual( + isUrlIgnored(urlToTest, ignoredUrls), + true, + urlIgnored + ); + } + }); + }); }); });