Unverified Commit b0d5d2d9 authored by Ian Hickson's avatar Ian Hickson Committed by GitHub

Escape path separator in regexps (#14122)

* Escape path separator in regexps

* Update platform_helper.dart

* Update stack_trace_test.dart

* Update stack_trace_test.dart
parent 2908997b
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'dart:io' show Platform;
/// Returns [Platform.pathSeparator], suitably escaped so as to be usable in a
/// regular expression.
String get pathSeparatorForRegExp {
switch (Platform.pathSeparator) {
case r'/':
return r'/';
case r'\':
return r'\\'; // because dividerRegExp gets inserted into regexps
default:
throw 'Unsupported platform.';
}
}
......@@ -2,21 +2,21 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'dart:io';
import 'package:flutter/foundation.dart';
import 'package:test/test.dart';
import 'platform_helper.dart';
void main() {
// TODO(8128): These tests and the filtering mechanism should be revisited to account for causal async stack traces.
final String divider = Platform.pathSeparator;
final String dividerRegExp = pathSeparatorForRegExp;
test('FlutterError.defaultStackFilter', () {
final List<String> filtered = FlutterError.defaultStackFilter(StackTrace.current.toString().trimRight().split('\n')).toList();
expect(filtered.length, greaterThanOrEqualTo(4));
expect(filtered[0], matches(r'^#0 +main\.<anonymous closure> \(.*stack_trace_test\.dart:[0-9]+:[0-9]+\)$'));
expect(filtered[1], matches(r'^#1 +Declarer\.test\.<anonymous closure>.<anonymous closure> \(package:test' + divider + r'.+:[0-9]+:[0-9]+\)$'));
expect(filtered[1], matches(r'^#1 +Declarer\.test\.<anonymous closure>.<anonymous closure> \(package:test' + dividerRegExp + r'.+:[0-9]+:[0-9]+\)$'));
expect(filtered[2], equals('<asynchronous suspension>'));
expect(filtered.last, matches(r'^\(elided [1-9][0-9]+ frames from package dart:async, package dart:async-patch, and package stack_trace\)$'));
});
......
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