mirror of
https://github.com/dart-lang/sdk
synced 2024-10-05 02:17:16 +00:00
Fix issue 24043: do not trust the pattern. Enable a 'hidden' test.
If there is a performance issues, I can add specialized code for String patterns. BUG=24043 R=rmacnak@google.com Review URL: https://codereview.chromium.org//1286823003 .
This commit is contained in:
parent
902c00a789
commit
56c91201c3
|
@ -896,14 +896,16 @@ class _StringBase {
|
|||
List<String> result = new List<String>();
|
||||
int startIndex = 0;
|
||||
int previousIndex = 0;
|
||||
// 'pattern' may not be implemented correctly and therefore we cannot
|
||||
// call _substringUnhchecked unless it is a trustworthy type (e.g. String).
|
||||
while (true) {
|
||||
if (startIndex == length || !iterator.moveNext()) {
|
||||
result.add(this._substringUnchecked(previousIndex, length));
|
||||
result.add(this.substring(previousIndex, length));
|
||||
break;
|
||||
}
|
||||
Match match = iterator.current;
|
||||
if (match.start == length) {
|
||||
result.add(this._substringUnchecked(previousIndex, length));
|
||||
result.add(this.substring(previousIndex, length));
|
||||
break;
|
||||
}
|
||||
int endIndex = match.end;
|
||||
|
@ -911,7 +913,7 @@ class _StringBase {
|
|||
++startIndex; // empty match, advance and restart
|
||||
continue;
|
||||
}
|
||||
result.add(this._substringUnchecked(previousIndex, match.start));
|
||||
result.add(this.substring(previousIndex, match.start));
|
||||
startIndex = previousIndex = endIndex;
|
||||
}
|
||||
return result;
|
||||
|
|
|
@ -5,6 +5,8 @@
|
|||
// Test to ensure that StringBuffer and string interpolation behaves
|
||||
// the same and fail fast.
|
||||
|
||||
import "package:expect/expect.dart";
|
||||
|
||||
class ToStringWrapper {
|
||||
final value;
|
||||
|
29
tests/language/string_split_test.dart
Normal file
29
tests/language/string_split_test.dart
Normal file
|
@ -0,0 +1,29 @@
|
|||
// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
|
||||
// for details. All rights reserved. Use of this source code is governed by a
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
// Issue 24043.
|
||||
|
||||
import "package:expect/expect.dart";
|
||||
|
||||
class EvilMatch implements Match {
|
||||
int get start => 100000000;
|
||||
int get end => 3;
|
||||
}
|
||||
|
||||
class EvilIterator implements Iterator {
|
||||
bool moveNext() => true;
|
||||
EvilMatch get current => new EvilMatch();
|
||||
}
|
||||
|
||||
class EvilIterable extends Iterable {
|
||||
Iterator get iterator => new EvilIterator();
|
||||
}
|
||||
|
||||
class EvilPattern {
|
||||
Iterable allMatches(String s) => new EvilIterable();
|
||||
}
|
||||
|
||||
void main() {
|
||||
Expect.throws(() => "foo".split(new EvilPattern())[0].length,
|
||||
(e) => e is RangeError);
|
||||
}
|
Loading…
Reference in a new issue