Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

spawnDomUri fails when resolving import urls in base64 encoded uris #18001

Closed
sigmundch opened this issue Apr 3, 2014 · 4 comments
Closed

spawnDomUri fails when resolving import urls in base64 encoded uris #18001

sigmundch opened this issue Apr 3, 2014 · 4 comments
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)

Comments

@sigmundch
Copy link
Member

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)

@sigmundch
Copy link
Member Author

Marked this as blocking #18007.

@vsmenon
Copy link
Member

vsmenon commented Apr 7, 2014

I think the code is written assuming the spawned URL is the package root. I.e., it can't be a package - it's the root for anything it's loading. It seems dangerous to inherit the spawner's package root - what becomes the root for anything a.dart imports? a.dart's directory - packages/a/packages?

Also, what do you mean by "nothing happens" in the relative case (ex 2)? The script has no main, so nothing should happen.

@sigmundch
Copy link
Member Author

what do you mean by "nothing happens" in the relative case (ex 2)? The script has no main, so nothing should happen.

There is a main, it's just a bit more hidden. Note that in that example the main function is generated with code in _spawn().

@kevmoo kevmoo added type-bug Incorrect behavior (everything from a crash to more subtle misbehavior) and removed priority-unassigned labels Feb 29, 2016
@jmesserly jmesserly added the closed-not-planned Closed as we don't intend to take action on the reported issue label Feb 28, 2018
@jmesserly
Copy link

we're removing dart:isolate from dart4web (and spawnDomUri was not implemented by JS compilers)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
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)
Projects
None yet
Development

No branches or pull requests

4 participants