Skip to content

Commit

Permalink
tracePropagationTargets ignores invalid Regex (#1043)
Browse files Browse the repository at this point in the history
  • Loading branch information
marandaneto authored Oct 4, 2022
1 parent 2deb645 commit 0d96d07
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
### Fixes

- Handle traces sampler exception ([#1040](https://github.com/getsentry/sentry-dart/pull/1040))
- tracePropagationTargets ignores invalid Regex ([#1043](https://github.com/getsentry/sentry-dart/pull/1043))

### Features

Expand Down
12 changes: 10 additions & 2 deletions dart/lib/src/utils/tracing_utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,18 @@ bool containsTracePropagationTarget(
return false;
}
for (final target in tracePropagationTargets) {
final regExp = RegExp(target, caseSensitive: false);
if (url.contains(target) || regExp.hasMatch(url)) {
if (url.contains(target)) {
return true;
}
try {
final regExp = RegExp(target, caseSensitive: false);
if (regExp.hasMatch(url)) {
return true;
}
} on FormatException {
// ignore invalid regex
continue;
}
}
return false;
}
Expand Down
10 changes: 9 additions & 1 deletion dart/test/utils/tracing_utils_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,15 @@ void main() {
isTrue);
expect(
containsTracePropagationTarget(origins, 'ftp://api.foo.bar:8080/foo'),
false);
isFalse);
});

test('invalid regex do not throw', () {
expect(
containsTracePropagationTarget(
['AABB???', '^(http|https)://api\\..*\$'],
'http://api.foo.bar:8080/foo'),
isTrue);
});

test('when no origins are defined, returns false for every url', () {
Expand Down

0 comments on commit 0d96d07

Please sign in to comment.