Standalone: Use new support in dart:core for decoding data uris.

R=iposva@google.com

Review URL: https://codereview.chromium.org/1489603002 .
This commit is contained in:
Ryan Macnak
2015-12-01 13:46:20 -08:00
parent 50d9ec3161
commit 6fc5018282
4 changed files with 16 additions and 38 deletions
+4 -20
View File
@@ -62,32 +62,16 @@ void _loadFile(SendPort sp, int id, Uri uri) {
});
}
var dataUriRegex = new RegExp(
r"data:([\w-]+/[\w-]+)?(;charset=([\w-]+))?(;base64)?,(.*)");
void _loadDataUri(SendPort sp, int id, Uri uri) {
try {
var match = dataUriRegex.firstMatch(uri.toString());
if (match == null) throw "Malformed data uri";
var mimeType = match.group(1);
var encoding = match.group(3);
var maybeBase64 = match.group(4);
var encodedData = match.group(5);
if (mimeType != "application/dart") {
if (uri.data.mimeType != "application/dart") {
throw "MIME-type must be application/dart";
}
if (encoding != "utf-8") {
// Default is ASCII. The C++ portion of the embedder assumes UTF-8.
if (uri.data.charset != "utf-8") {
// The C++ portion of the embedder assumes UTF-8.
throw "Only utf-8 encoding is supported";
}
if (maybeBase64 != null) {
throw "Only percent encoding is supported";
}
var data = UTF8.encode(Uri.decodeComponent(encodedData));
_sendResourceResponse(sp, id, data);
_sendResourceResponse(sp, id, uri.data.contentAsBytes());
} catch (e) {
_sendResourceResponse(sp, id, "Invalid data uri ($uri):\n $e");
}
@@ -1,13 +0,0 @@
// Copyright (c) 2015, 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.
import 'data:text/plain;charset=utf-8,foo%28%29%20%3D%3E%2042%3B'; /// wrongmime: ok
import 'data:;charset=utf-8,foo%28%29%20%3D%3E%2042%3B'; /// nomime: ok
import 'data:application/dart;charset=utf-16,foo%28%29%20%3D%3E%2042%3B'; /// utf16: runtime error
import 'data:application/dart,foo%28%29%20%3D%3E%2042%3B'; /// nocharset: ok
import 'data:application/dart;charset=utf-8,foo?%9g'; /// badencodeddate: runtime error
import 'data:application/dart;charset=utf-8;base64,Zm9vKCkgPT4gNDI7'; /// base64: ok
main() {
}
@@ -3,7 +3,13 @@
// BSD-style license that can be found in the LICENSE file.
// foo() => 42;
import 'data:application/dart;charset=utf-8,foo%28%29%20%3D%3E%2042%3B';
import 'data:application/dart;charset=utf-8,foo%28%29%20%3D%3E%2042%3B'; /// percentencoded: ok
import 'data:text/plain;charset=utf-8,foo%28%29%20%3D%3E%2042%3B'; /// wrongmime: ok
import 'data:;charset=utf-8,foo%28%29%20%3D%3E%2042%3B'; /// nomime: ok
import 'data:application/dart;charset=utf-16,foo%28%29%20%3D%3E%2042%3B'; /// utf16: runtime error
import 'data:application/dart,foo%28%29%20%3D%3E%2042%3B'; /// nocharset: ok
import 'data:application/dart;charset=utf-8,foo?%9g'; /// badencodeddate: runtime error
import 'data:application/dart;charset=utf-8;base64,Zm9vKCkgPT4gNDI7'; /// base64: ok
import "package:expect/expect.dart";
+5 -4
View File
@@ -12,6 +12,8 @@ cc/SNPrint_BadArgs: Skip
# Flaky on buildbot. Issue 5133 and 10409.
cc/Sleep: Pass, Fail
dart/data_uri_import_test/none: SkipByDesign
[ $mode == debug ]
# This is a benchmark that is not informative in debug mode.
cc/CorelibIsolateStartup: Skip
@@ -56,10 +58,9 @@ dart/inline_stack_frame_test: RuntimeError, Pass # Issue 7953
dart/data_uri*test: Skip
[ $runtime == vm ]
dart/data_uri_failures_test/wrongmime: RuntimeError, OK # VM is more restrictive than the browser
dart/data_uri_failures_test/nomime: RuntimeError, OK
dart/data_uri_failures_test/nocharset: RuntimeError, OK
dart/data_uri_failures_test/base64: RuntimeError, OK
dart/data_uri_import_test/wrongmime: RuntimeError, OK # VM is more restrictive than the browser
dart/data_uri_import_test/nomime: RuntimeError, OK
dart/data_uri_import_test/nocharset: RuntimeError, OK
[ $arch == mips ]
cc/StaticNonNullSumCallCodegen: Crash, Pass # Issue 17440