Skip to content

Commit

Permalink
fix(core): support regex global flag in urlMatches (#2560)
Browse files Browse the repository at this point in the history
Co-authored-by: Daniel Dyla <dyladan@users.noreply.github.com>
  • Loading branch information
moander and dyladan authored Oct 27, 2021
1 parent c1939a7 commit c0ab952
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/opentelemetry-core/src/utils/url.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
/**
Expand Down
13 changes: 13 additions & 0 deletions packages/opentelemetry-core/test/utils/url.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,5 +71,18 @@ describe('Core - Utils - url', () => {
);
});
});
describe('when regex has global flag', () => {
it('should return true', () => {
const ignoredUrls = [/myaddr/g];
// Run test multiple times to ensure same result (git.io/JimS1)
for (let i = 0; i < 3; i++) {
assert.strictEqual(
isUrlIgnored(urlToTest, ignoredUrls),
true,
urlIgnored
);
}
});
});
});
});

0 comments on commit c0ab952

Please sign in to comment.