spawnDomUri fails when resolving import urls in base64 encoded uris #18001
Labels
closed-not-planned
Closed as we don't intend to take action on the reported issue
type-bug
Incorrect behavior (everything from a crash to more subtle misbehavior)
spawnDomUri API fails to resolve relative and "package:" uris in code encoded into a base64 URIs.
I'd assume these URIs should be resolved in terms of the window baseUri, but it doesn't seem that way. Here is a repro example:
bug.html:
<script type="application/dart">
import 'dart:html';
main() {
var baseUri = Uri.parse(window.location.href);
// Spawning code in other files works:
spawnDomUri(baseUri.resolve('b.dart'), [], ''); // works
spawnDomUri(baseUri.resolve('c.dart'), [], ''); // works
// Code that contains absolute URIs work too:
_spawn(baseUri.resolve("packages/a/a.dart"), 1); // works
// I'd expect these two examples to work in the same way:
_spawn("packages/a/a.dart", 2); // nothing happens?
_spawn("package:a/a.dart", 3); // fails
}
_spawn(String importUrl, int i) {
var code = 'import "$importUrl";\nmain() => print("$value [data-uri-$i]");';
// ignore the mime-type below, see issue #0
var encoded = 'data:text/javascript;base64,${window.btoa(code)}';
spawnDomUri(Uri.parse(encoded), [], '');
}
</script>
packages/a/a.dart:
const value = "hello world";
b.dart:
import 'packages/a/a.dart';
main() => print('$value [b]');
c.dart:
import 'package:a/a.dart';
main() => print('$value [c]');
I see no output on the example labeled with #2, but a failure as follows on example #3:
'package:a/a.dart': error: line 1 pos 1: unexpected token '<'
<script type="application/dart">
^: package:a/a.dart package:a/a.dart:1
Internal error: 'package:a/a.dart': error: line 1 pos 1: unexpected token '<'
<script type="application/dart">
^
(FYI the error line seems to match the code of bug.html)
If I set DART_PACKAGE_ROOT then the example #3 above works.
Attachment:
spawnuri_bug.tgz (627 Bytes)
The text was updated successfully, but these errors were encountered: