Fix stack filtering (#49956)
This commit is contained in:
parent
64b82f50ad
commit
ccf5d641c5
@ -126,7 +126,7 @@ class RepetitiveStackFrameFilter extends StackFilter {
|
||||
|
||||
@override
|
||||
void filter(List<StackFrame> stackFrames, List<String> reasons) {
|
||||
for (int index = 0; index < stackFrames.length; index += 1) {
|
||||
for (int index = 0; index < stackFrames.length - numFrames; index += 1) {
|
||||
if (_matchesFrames(stackFrames.skip(index).take(numFrames).toList())) {
|
||||
reasons.setRange(index, index + numFrames, _replacements);
|
||||
index += numFrames - 1;
|
||||
@ -135,6 +135,9 @@ class RepetitiveStackFrameFilter extends StackFilter {
|
||||
}
|
||||
|
||||
bool _matchesFrames(List<StackFrame> stackFrames) {
|
||||
if (stackFrames.length < numFrames) {
|
||||
return false;
|
||||
}
|
||||
for (int index = 0; index < stackFrames.length; index++) {
|
||||
if (!frames[index].matches(stackFrames[index])) {
|
||||
return false;
|
||||
|
@ -428,4 +428,24 @@ void main() {
|
||||
expect(trace, isNotNull);
|
||||
expect(trace.value, stack);
|
||||
});
|
||||
|
||||
test('RepetitiveStackFrameFilter does not go out of range', () {
|
||||
const RepetitiveStackFrameFilter filter = RepetitiveStackFrameFilter(
|
||||
frames: <PartialStackFrame>[
|
||||
PartialStackFrame(className: 'TestClass', method: 'test1', package: 'package:test/blah.dart'),
|
||||
PartialStackFrame(className: 'TestClass', method: 'test2', package: 'package:test/blah.dart'),
|
||||
PartialStackFrame(className: 'TestClass', method: 'test3', package: 'package:test/blah.dart'),
|
||||
],
|
||||
replacement: 'test',
|
||||
);
|
||||
final List<String> reasons = List<String>(2);
|
||||
filter.filter(
|
||||
const <StackFrame>[
|
||||
StackFrame(className: 'TestClass', method: 'test1', packageScheme: 'package', package: 'test', packagePath: 'blah.dart', line: 1, column: 1, number: 0, source: ''),
|
||||
StackFrame(className: 'TestClass', method: 'test2', packageScheme: 'package', package: 'test', packagePath: 'blah.dart', line: 1, column: 1, number: 0, source: ''),
|
||||
],
|
||||
reasons,
|
||||
);
|
||||
expect(reasons, List<String>(2));
|
||||
});
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user