@@ -28,8 +28,8 @@ class ResourceUrlResolver {
28
28
static final RegExp urlTemplateSearch = new RegExp ('{{.*}}' );
29
29
static final RegExp quotes = new RegExp ("[\"\' ]" );
30
30
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 ( );
33
33
34
34
final TypeToUriMapper _uriMapper;
35
35
final ResourceResolverConfig _config;
@@ -39,7 +39,15 @@ class ResourceUrlResolver {
39
39
static final NodeTreeSanitizer _nullTreeSanitizer = new _NullTreeSanitizer ();
40
40
static final docForParsing = document.implementation.createHtmlDocument ('' );
41
41
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) {
43
51
var div = docForParsing.createElement ('div' );
44
52
div.setInnerHtml (html, treeSanitizer: _nullTreeSanitizer);
45
53
return div;
@@ -49,9 +57,9 @@ class ResourceUrlResolver {
49
57
if (baseUri == null ) {
50
58
return html;
51
59
}
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;
55
63
}
56
64
57
65
/**
0 commit comments