| Index: frog/leg/scanner/byte_strings.dart
|
| diff --git a/frog/leg/scanner/byte_strings.dart b/frog/leg/scanner/byte_strings.dart
|
| index 8cbe6a9085ef4dea60f6e470c245a8d08a41b531..17777fcafd5fa9e4e4cf79f0407b159d5f670fe0 100644
|
| --- a/frog/leg/scanner/byte_strings.dart
|
| +++ b/frog/leg/scanner/byte_strings.dart
|
| @@ -109,27 +109,17 @@ class Utf8String extends ByteString {
|
| Iterator<int> iterator() => new Utf8Decoder(bytes, 0, length);
|
|
|
| SourceString copyWithoutQuotes(int initial, int terminal) {
|
| - assert(0 <= initial && initial <= 4);
|
| - assert(initial !== 1 || bytes[offset] === $SQ ||
|
| - bytes[offset] === $DQ);
|
| - assert(initial !== 2 || (bytes[offset] === $AT &&
|
| - (bytes[offset + 1] === $SQ ||
|
| - bytes[offset + 1] === $DQ)));
|
| - assert(initial !== 3 || ((bytes[offset] === $SQ ||
|
| - bytes[offset] === $DQ) &&
|
| - bytes[offset] === bytes[offset + 1] &&
|
| - bytes[offset] === bytes[offset + 2]));
|
| - assert(initial !== 4 || (bytes[offset] === $AT &&
|
| - (bytes[offset + 1] === $SQ ||
|
| - bytes[offset + 1] === $DQ) &&
|
| - bytes[offset + 2] === bytes[offset + 1] &&
|
| - bytes[offset + 3] === bytes[offset + 1]));
|
| - assert(terminal === 0 || terminal === 1 || terminal === 3);
|
| - assert(terminal === 0 || ((bytes[end - 1] == $AT ||
|
| - bytes[end - 1] === $DQ) &&
|
| - (terminal === 1 ||
|
| - bytes[end - 2] === bytes[end - 1] &&
|
| - bytes[end - 3] === bytes[end - 1])));
|
| + assert((){
|
| + // Only allow dropping ASCII characters, to guarantee that
|
| + // the resulting Utf8String is still valid.
|
| + for (int i = 0; i < initial; i++) {
|
| + if (bytes[offset + i] >= 0x80) return false;
|
| + }
|
| + for (int i = 0; i < terminal; i++) {
|
| + if (bytes[offset + length - terminal + i] >= 0x80) return false;
|
| + }
|
| + return true;
|
| + });
|
| // TODO(lrn): Check that first and last bytes use the same type of quotes.
|
| return new Utf8String(bytes, offset + initial,
|
| length - initial - terminal);
|
|
|