Skip to content

Commit 0d96d07

Browse files
authored
tracePropagationTargets ignores invalid Regex (#1043)
1 parent 2deb645 commit 0d96d07

File tree

3 files changed

+20
-3
lines changed

3 files changed

+20
-3
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
### Fixes
66

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

910
### Features
1011

dart/lib/src/utils/tracing_utils.dart

+10-2
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,18 @@ bool containsTracePropagationTarget(
4646
return false;
4747
}
4848
for (final target in tracePropagationTargets) {
49-
final regExp = RegExp(target, caseSensitive: false);
50-
if (url.contains(target) || regExp.hasMatch(url)) {
49+
if (url.contains(target)) {
5150
return true;
5251
}
52+
try {
53+
final regExp = RegExp(target, caseSensitive: false);
54+
if (regExp.hasMatch(url)) {
55+
return true;
56+
}
57+
} on FormatException {
58+
// ignore invalid regex
59+
continue;
60+
}
5361
}
5462
return false;
5563
}

dart/test/utils/tracing_utils_test.dart

+9-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,15 @@ void main() {
3535
isTrue);
3636
expect(
3737
containsTracePropagationTarget(origins, 'ftp://api.foo.bar:8080/foo'),
38-
false);
38+
isFalse);
39+
});
40+
41+
test('invalid regex do not throw', () {
42+
expect(
43+
containsTracePropagationTarget(
44+
['AABB???', '^(http|https)://api\\..*\$'],
45+
'http://api.foo.bar:8080/foo'),
46+
isTrue);
3947
});
4048

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

0 commit comments

Comments
 (0)