Skip to content
This repository has been archived by the owner on Feb 22, 2018. It is now read-only.

Commit

Permalink
fix(url_resolver): changes _baseUri to support non http schemes.
Browse files Browse the repository at this point in the history
Adds support for Chrome Apps because Uri.base.origin is
limited to scheme that start with http or https.
  • Loading branch information
Kleak authored and rkirov committed Jan 14, 2015
1 parent 6bf7eaa commit d929109
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions lib/core_dom/resource_url_resolver.dart
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ class ResourceUrlResolver {
static final RegExp urlTemplateSearch = new RegExp('{{.*}}');
static final RegExp quotes = new RegExp("[\"\']");

// Ensures that Uri.base is http/https.
final _baseUri = Uri.base.origin + ('/');
// Reconstruct the Uri without the http or https restriction due to Uri.base.origin
final _baseUri = _getBaseUri();

final TypeToUriMapper _uriMapper;
final ResourceResolverConfig _config;
Expand All @@ -39,7 +39,15 @@ class ResourceUrlResolver {
static final NodeTreeSanitizer _nullTreeSanitizer = new _NullTreeSanitizer();
static final docForParsing = document.implementation.createHtmlDocument('');

static Node _parseHtmlString(String html) {
static String _getBaseUri() {
if (Uri.base.authority.isEmpty) {
throw "Relative URL resolution requires a valid base URI";
} else {
return "${Uri.base.scheme}://${Uri.base.authority}/";
}
}

static Element _parseHtmlString(String html) {
var div = docForParsing.createElement('div');
div.setInnerHtml(html, treeSanitizer: _nullTreeSanitizer);
return div;
Expand All @@ -49,9 +57,9 @@ class ResourceUrlResolver {
if (baseUri == null) {
return html;
}
Node node = _parseHtmlString(html);
_resolveDom(node, baseUri);
return node.innerHtml;
Element elem = _parseHtmlString(html);
_resolveDom(elem, baseUri);
return elem.innerHtml;
}

/**
Expand Down

3 comments on commit d929109

@andrej-kolic
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This commit made angular dart applications unusable for Cordova / PhoneGap as they load resources locally (file:///url_to_resource).

Is there any solution for this problem besides providing custom implementation for ResourceUrlResolver through DI?

@rkirov
Copy link
Contributor

@rkirov rkirov commented on d929109 Feb 25, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should allow empty authority if the scheme is file. Should be a pretty straighforward change.

Also these failures mean our test coverage is lacking. So we need tests covering the major use cases - web, chrome apps, Cordova etc.

@chirayu do you agree?

@Kleak
Copy link
Contributor Author

@Kleak Kleak commented on d929109 Nov 13, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can update the code to allow an empty authority in the case where scheme is file

Please sign in to comment.