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

Commit d929109

Browse files
kevin-sakemaerrkirov
authored andcommitted
fix(url_resolver): changes _baseUri to support non http schemes.
Adds support for Chrome Apps because Uri.base.origin is limited to scheme that start with http or https.
1 parent 6bf7eaa commit d929109

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

lib/core_dom/resource_url_resolver.dart

100644100755
Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ class ResourceUrlResolver {
2828
static final RegExp urlTemplateSearch = new RegExp('{{.*}}');
2929
static final RegExp quotes = new RegExp("[\"\']");
3030

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

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

42-
static Node _parseHtmlString(String html) {
42+
static String _getBaseUri() {
43+
if (Uri.base.authority.isEmpty) {
44+
throw "Relative URL resolution requires a valid base URI";
45+
} else {
46+
return "${Uri.base.scheme}://${Uri.base.authority}/";
47+
}
48+
}
49+
50+
static Element _parseHtmlString(String html) {
4351
var div = docForParsing.createElement('div');
4452
div.setInnerHtml(html, treeSanitizer: _nullTreeSanitizer);
4553
return div;
@@ -49,9 +57,9 @@ class ResourceUrlResolver {
4957
if (baseUri == null) {
5058
return html;
5159
}
52-
Node node = _parseHtmlString(html);
53-
_resolveDom(node, baseUri);
54-
return node.innerHtml;
60+
Element elem = _parseHtmlString(html);
61+
_resolveDom(elem, baseUri);
62+
return elem.innerHtml;
5563
}
5664

5765
/**

0 commit comments

Comments
 (0)