Skip to content

Commit

Permalink
Version 0.6.21.3
Browse files Browse the repository at this point in the history
  • Loading branch information
ricowind committed May 27, 2015
1 parent 3434d6b commit df6ae38
Show file tree
Hide file tree
Showing 76 changed files with 556 additions and 902 deletions.
2 changes: 1 addition & 1 deletion pkg/analyzer_experimental/bin/analyzer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ class BatchRunner {
ErrorSeverity batchResult = ErrorSeverity.NONE;
// read line from stdin
Stream cmdLine = stdin
.transform(new StringDecoder())
.transform(UTF8.decoder)
.transform(new LineSplitter());
var subscription = cmdLine.listen((String line) {
// may be finish
Expand Down
2 changes: 1 addition & 1 deletion pkg/analyzer_experimental/bin/formatter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ _formatFile(path) {
var buffer = new StringBuffer();
var file = new File(path);
file.openRead()
.transform(new StringDecoder())
.transform(UTF8.decoder)
.listen((data) => buffer.write(data),
onError: (error) => print('Error, could not open "$path"'),
onDone: () => print(_formatCU(buffer.toString())));
Expand Down
16 changes: 5 additions & 11 deletions pkg/barback/lib/src/asset.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
library barback.asset;

import 'dart:async';
import 'dart:convert' show Encoding, UTF8;
import 'dart:io';
import 'dart:utf';

Expand Down Expand Up @@ -37,7 +38,7 @@ abstract class Asset {
///
/// If the asset was created from a [String] the original string is always
/// returned and [encoding] is ignored. Otherwise, the binary data of the
/// asset is decoded using [encoding], which defaults to [Encoding.UTF_8].
/// asset is decoded using [encoding], which defaults to [UTF8].
Future<String> readAsString({Encoding encoding});

/// Streams the binary contents of the asset.
Expand All @@ -54,16 +55,9 @@ class _BinaryAsset extends Asset {
: super(id);

Future<String> readAsString({Encoding encoding}) {
if (encoding == null) encoding = Encoding.UTF_8;
if (encoding == null) encoding = UTF8;

// TODO(rnystrom): When #6284 is fixed, just use that. Until then, only
// UTF-8 is supported. :(
if (encoding != Encoding.UTF_8) {
throw new UnsupportedError(
"${encoding.name} is not a supported encoding.");
}

return new Future.value(decodeUtf8(_contents));
return new Future.value(encoding.decode(_contents));
}

Stream<List<int>> read() => new Future<List<int>>.value(_contents).asStream();
Expand Down Expand Up @@ -104,7 +98,7 @@ class _FileAsset extends Asset {
: super(id);

Future<String> readAsString({Encoding encoding}) {
if (encoding == null) encoding = Encoding.UTF_8;
if (encoding == null) encoding = UTF8;
return _file.readAsString(encoding: encoding);
}

Expand Down
5 changes: 3 additions & 2 deletions pkg/barback/test/asset_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
library barback.test.asset_test;

import 'dart:async';
import 'dart:convert' show Encoding, UTF8, LATIN1;
import 'dart:io';
import 'dart:utf';

Expand Down Expand Up @@ -108,7 +109,7 @@ main() {

test("supports UTF-8", () {
var asset = new Asset.fromBytes(id, encodeUtf8("çøñ†éℵ™"));
expect(asset.readAsString(encoding: Encoding.UTF_8),
expect(asset.readAsString(encoding: UTF8),
completion(equals("çøñ†éℵ™")));
});

Expand All @@ -124,7 +125,7 @@ main() {

test("ignores the encoding", () {
var asset = new Asset.fromString(id, "contents");
expect(asset.readAsString(encoding: Encoding.ISO_8859_1),
expect(asset.readAsString(encoding: LATIN1),
completion(equals("contents")));
});
});
Expand Down
1 change: 1 addition & 0 deletions pkg/barback/test/utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ library barback.test.utils;

import 'dart:async';
import 'dart:collection';
import 'dart:convert' show Encoding;
import 'dart:io';

import 'package:barback/barback.dart';
Expand Down
11 changes: 6 additions & 5 deletions pkg/http/lib/src/byte_stream.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
library byte_stream;

import 'dart:async';
import 'dart:convert';
import 'dart:io';
import 'dart:typed_data';

Expand All @@ -30,10 +31,10 @@ class ByteStream extends StreamView<List<int>> {
}

/// Collect the data of this stream in a [String], decoded according to
/// [encoding], which defaults to `Encoding.UTF_8`.
Future<String> bytesToString([Encoding encoding=Encoding.UTF_8]) =>
toBytes().then((bytes) => decodeString(bytes, encoding));
/// [encoding], which defaults to `UTF8`.
Future<String> bytesToString([Encoding encoding=UTF8]) =>
toBytes().then((bytes) => encoding.decode(bytes));

Stream<String> toStringStream([Encoding encoding=Encoding.UTF_8]) =>
transform(new StringDecoder(encoding));
Stream<String> toStringStream([Encoding encoding=UTF8]) =>
transform(encoding.decoder);
}
5 changes: 3 additions & 2 deletions pkg/http/lib/src/multipart_file.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
library multipart_file;

import 'dart:async';
import 'dart:convert';
import 'dart:io';

import 'package:path/path.dart' as path;
Expand Down Expand Up @@ -70,14 +71,14 @@ class MultipartFile {
contentType = contentType == null ? new ContentType("text", "plain")
: contentType;
var charset = contentType.charset;
var encoding = encodingForCharset(contentType.charset, Encoding.UTF_8);
var encoding = encodingForCharset(contentType.charset, UTF8);
// Make a new contentType with ensured charset.
contentType = new ContentType(contentType.primaryType,
contentType.subType,
charset: encoding.name,
parameters: contentType.parameters);

return new MultipartFile.fromBytes(field, encodeString(value, encoding),
return new MultipartFile.fromBytes(field, encoding.encode(value),
filename: filename,
contentType: contentType);
}
Expand Down
9 changes: 5 additions & 4 deletions pkg/http/lib/src/request.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

library request;

import 'dart:convert';
import 'dart:io';
import 'dart:typed_data';

Expand Down Expand Up @@ -36,7 +37,7 @@ class Request extends BaseRequest {
/// If the request has a `Content-Type` header and that header has a `charset`
/// parameter, that parameter's value is used as the encoding. Otherwise, if
/// [encoding] has been set manually, that encoding is used. If that hasn't
/// been set either, this defaults to [Encoding.UTF_8].
/// been set either, this defaults to [UTF8].
///
/// If the `charset` parameter's value is not a known [Encoding], reading this
/// will throw a [FormatException].
Expand Down Expand Up @@ -83,10 +84,10 @@ class Request extends BaseRequest {
/// header, one will be added with the type `text/plain`. Then the `charset`
/// parameter of the `Content-Type` header (whether new or pre-existing) will
/// be set to [encoding] if it wasn't already set.
String get body => decodeString(bodyBytes, encoding);
String get body => encoding.decode(bodyBytes);

set body(String value) {
bodyBytes = encodeString(value, encoding);
bodyBytes = encoding.encode(value);
var contentType = _contentType;
if (contentType == null) {
contentType = new ContentType("text", "plain", charset: encoding.name);
Expand Down Expand Up @@ -137,7 +138,7 @@ class Request extends BaseRequest {
/// Creates a new HTTP request.
Request(String method, Uri url)
: super(method, url),
_defaultEncoding = Encoding.UTF_8,
_defaultEncoding = UTF8,
_bodyBytes = new Uint8List(0);

/// Freezes all mutable fields and returns a single-subscription [ByteStream]
Expand Down
9 changes: 5 additions & 4 deletions pkg/http/lib/src/response.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
library response;

import 'dart:async';
import 'dart:convert';
import 'dart:io';
import 'dart:typed_data';

Expand All @@ -21,10 +22,10 @@ class Response extends BaseResponse {
/// The body of the response as a string. This is converted from [bodyBytes]
/// using the `charset` parameter of the `Content-Type` header field, if
/// available. If it's unavailable or if the encoding name is unknown,
/// [Encoding.ISO_8859_1] is used by default, as per [RFC 2616][].
/// [LATIN1] is used by default, as per [RFC 2616][].
///
/// [RFC 2616]: http://www.w3.org/Protocols/rfc2616/rfc2616-sec3.html
String get body => decodeString(bodyBytes, _encodingForHeaders(headers));
String get body => _encodingForHeaders(headers).decode(bodyBytes);

/// Creates a new HTTP response with a string body.
Response(
Expand All @@ -36,7 +37,7 @@ class Response extends BaseResponse {
bool persistentConnection: true,
String reasonPhrase})
: this.bytes(
encodeString(body, _encodingForHeaders(headers)),
_encodingForHeaders(headers).encode(body),
statusCode,
request: request,
headers: headers,
Expand Down Expand Up @@ -80,7 +81,7 @@ class Response extends BaseResponse {
}

/// Returns the encoding to use for a response with the given headers. This
/// defaults to [Encoding.ISO_8859_1] if the headers don't specify a charset or
/// defaults to [LATIN1] if the headers don't specify a charset or
/// if that charset is unknown.
Encoding _encodingForHeaders(Map<String, String> headers) =>
encodingForCharset(_contentTypeForHeaders(headers).charset);
Expand Down
20 changes: 4 additions & 16 deletions pkg/http/lib/src/utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
library utils;

import 'dart:async';
import 'dart:convert';
import 'dart:io';
import 'dart:typed_data';
import 'dart:utf';

import 'byte_stream.dart';

Expand Down Expand Up @@ -66,9 +66,9 @@ List<String> split1(String toSplit, String pattern) {
/// [charset] is null or if no [Encoding] was found that corresponds to
/// [charset].
Encoding encodingForCharset(
String charset, [Encoding fallback = Encoding.ISO_8859_1]) {
String charset, [Encoding fallback = LATIN1]) {
if (charset == null) return fallback;
var encoding = Encoding.fromName(charset);
var encoding = Encoding.getByName(charset);
return encoding == null ? fallback : encoding;
}

Expand All @@ -77,23 +77,11 @@ Encoding encodingForCharset(
/// [FormatException] if no [Encoding] was found that corresponds to [charset].
/// [charset] may not be null.
Encoding requiredEncodingForCharset(String charset) {
var encoding = Encoding.fromName(charset);
var encoding = Encoding.getByName(charset);
if (encoding != null) return encoding;
throw new FormatException('Unsupported encoding "$charset".');
}

/// Converts [bytes] into a [String] according to [encoding].
String decodeString(List<int> bytes, Encoding encoding) {
// TODO(nweiz): implement this once issue 6284 is fixed.
return decodeUtf8(bytes);
}

/// Converts [string] into a byte array according to [encoding].
List<int> encodeString(String string, Encoding encoding) {
// TODO(nweiz): implement this once issue 6284 is fixed.
return encodeUtf8(string);
}

/// A regular expression that matches strings that are composed entirely of
/// ASCII-compatible characters.
final RegExp _ASCII_ONLY = new RegExp(r"^[\x00-\x7F]+$");
Expand Down
29 changes: 15 additions & 14 deletions pkg/http/test/request_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

library request_test;

import 'dart:convert';
import 'dart:io';

import 'package:http/http.dart' as http;
Expand Down Expand Up @@ -62,32 +63,32 @@ void main() {
group('#encoding', () {
test('defaults to utf-8', () {
var request = new http.Request('POST', dummyUrl);
expect(request.encoding.name, equals(Encoding.UTF_8.name));
expect(request.encoding.name, equals(UTF8.name));
});

test('can be set', () {
var request = new http.Request('POST', dummyUrl);
request.encoding = Encoding.ISO_8859_1;
expect(request.encoding.name, equals(Encoding.ISO_8859_1.name));
request.encoding = LATIN1;
expect(request.encoding.name, equals(LATIN1.name));
});

test('is based on the content-type charset if it exists', () {
var request = new http.Request('POST', dummyUrl);
request.headers[HttpHeaders.CONTENT_TYPE] =
'text/plain; charset=iso-8859-1';
expect(request.encoding.name, equals(Encoding.ISO_8859_1.name));
expect(request.encoding.name, equals(LATIN1.name));
});

test('remains the default if the content-type charset is set and unset',
() {
var request = new http.Request('POST', dummyUrl);
request.encoding = Encoding.ISO_8859_1;
request.encoding = LATIN1;
request.headers[HttpHeaders.CONTENT_TYPE] =
'text/plain; charset=utf-8';
expect(request.encoding.name, equals(Encoding.UTF_8.name));
expect(request.encoding.name, equals(UTF8.name));

request.headers.remove(HttpHeaders.CONTENT_TYPE);
expect(request.encoding.name, equals(Encoding.ISO_8859_1.name));
expect(request.encoding.name, equals(LATIN1.name));
});

test('throws an error if the content-type charset is unknown', () {
Expand Down Expand Up @@ -240,7 +241,7 @@ void main() {

test('defaults to empty if only encoding is set', () {
var request = new http.Request('POST', dummyUrl);
request.encoding = Encoding.ISO_8859_1;
request.encoding = LATIN1;
expect(request.headers[HttpHeaders.CONTENT_TYPE], isNull);
});

Expand All @@ -255,7 +256,7 @@ void main() {
test('is set to application/x-www-form-urlencoded with the given charset '
'if bodyFields and encoding are set', () {
var request = new http.Request('POST', dummyUrl);
request.encoding = Encoding.ISO_8859_1;
request.encoding = LATIN1;
request.bodyFields = {'hello': 'world'};
expect(request.headers[HttpHeaders.CONTENT_TYPE],
equals('application/x-www-form-urlencoded; charset=iso-8859-1'));
Expand All @@ -264,7 +265,7 @@ void main() {
test('is set to text/plain and the given encoding if body and encoding are '
'both set', () {
var request = new http.Request('POST', dummyUrl);
request.encoding = Encoding.ISO_8859_1;
request.encoding = LATIN1;
request.body = 'hello, world';
expect(request.headers[HttpHeaders.CONTENT_TYPE],
equals('text/plain; charset=iso-8859-1'));
Expand All @@ -281,7 +282,7 @@ void main() {
test('is modified to include the given encoding if encoding is set', () {
var request = new http.Request('POST', dummyUrl);
request.headers[HttpHeaders.CONTENT_TYPE] = 'application/json';
request.encoding = Encoding.ISO_8859_1;
request.encoding = LATIN1;
expect(request.headers[HttpHeaders.CONTENT_TYPE],
equals('application/json; charset=iso-8859-1'));
});
Expand All @@ -290,7 +291,7 @@ void main() {
var request = new http.Request('POST', dummyUrl);
request.headers[HttpHeaders.CONTENT_TYPE] =
'application/json; charset=utf-8';
request.encoding = Encoding.ISO_8859_1;
request.encoding = LATIN1;
expect(request.headers[HttpHeaders.CONTENT_TYPE],
equals('application/json; charset=iso-8859-1'));
});
Expand Down Expand Up @@ -350,8 +351,8 @@ void main() {
var request = new http.Request('POST', dummyUrl);
request.finalize();

expect(request.encoding.name, equals(Encoding.UTF_8.name));
expect(() => request.encoding = Encoding.ASCII, throwsStateError);
expect(request.encoding.name, equals(UTF8.name));
expect(() => request.encoding = ASCII, throwsStateError);
});

test('freezes #bodyBytes', () {
Expand Down
Loading

0 comments on commit df6ae38

Please sign in to comment.