Unverified Commit ccf5d641 authored by Dan Field's avatar Dan Field Committed by GitHub

Fix stack filtering (#49956)

parent 64b82f50
......@@ -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));
});
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment