From 6fc5018282aba2e5cea0f4bbcf0a9e0126917890 Mon Sep 17 00:00:00 2001 From: Ryan Macnak Date: Tue, 1 Dec 2015 13:46:20 -0800 Subject: [PATCH] Standalone: Use new support in dart:core for decoding data uris. R=iposva@google.com Review URL: https://codereview.chromium.org/1489603002 . --- runtime/bin/vmservice/loader.dart | 24 ++++--------------- .../tests/vm/dart/data_uri_failures_test.dart | 13 ---------- .../tests/vm/dart/data_uri_import_test.dart | 8 ++++++- runtime/tests/vm/vm.status | 9 +++---- 4 files changed, 16 insertions(+), 38 deletions(-) delete mode 100644 runtime/tests/vm/dart/data_uri_failures_test.dart diff --git a/runtime/bin/vmservice/loader.dart b/runtime/bin/vmservice/loader.dart index cd94f579ba0..38b62b171a8 100644 --- a/runtime/bin/vmservice/loader.dart +++ b/runtime/bin/vmservice/loader.dart @@ -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"); } diff --git a/runtime/tests/vm/dart/data_uri_failures_test.dart b/runtime/tests/vm/dart/data_uri_failures_test.dart deleted file mode 100644 index 2df31950f38..00000000000 --- a/runtime/tests/vm/dart/data_uri_failures_test.dart +++ /dev/null @@ -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() { -} \ No newline at end of file diff --git a/runtime/tests/vm/dart/data_uri_import_test.dart b/runtime/tests/vm/dart/data_uri_import_test.dart index 2430b9528a8..8ce4e1adb69 100644 --- a/runtime/tests/vm/dart/data_uri_import_test.dart +++ b/runtime/tests/vm/dart/data_uri_import_test.dart @@ -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"; diff --git a/runtime/tests/vm/vm.status b/runtime/tests/vm/vm.status index 3f996da96cb..6ac07aad238 100644 --- a/runtime/tests/vm/vm.status +++ b/runtime/tests/vm/vm.status @@ -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