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(core): support regex global flag in urlMatches #2560

Merged
merged 2 commits into from
Oct 27, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
);
}
});
});
});
});