Tools: HTML document `<base href="...">` does not influence import scanning.

Created on 28 Jan 2017  路  6Comments  路  Source: Polymer/tools

Discovered while working on polymer-bundler to implement <base> tag handling, I discovered that calling document.getByKind('import') on my analyzed document, the set returned did not include all the expected transitive dependencies. The point of disconnect was an imported document that included a <base> tag which modified the intent of its href and src attributes etc.

Propose extending the analyzer to make document "base url" a thing different but derived from the document url and properly identify such when <base> present in an HTML document.

analyzer High Accepted Bug

Most helpful comment

Quickly, I think there are two changes to do. First, ParsedHtmlDocument, or possibly ParsedDocument, should get a baseUrl property and a resolveUrl() method. Second HtmlImportScanner and friends need to use that.

@rictic jinx

All 6 comments

+1

Do you have an example document easily available?

My test is these four documents.

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8">
    <link rel="import" href="imports/base.html">
    <title></title>
  </head>
  <body>
  </body>
</html>
<base href="base-foo">
<link rel="import" href="sub-base.html">
<base href="../../imports">
<link rel="import" href="super-base.html">
<span href="hello">From Sub-Base!</span>
<a href="sub-base/sub-base.html">Hello also from super base!</a>

Good catch.

Seems like in addition to those tests we need a simple root with a base tag.

Seems like, since multiple scanners will want this info, this would be a good thing to put on the ParsedHtmlDocument when we produce it

Quickly, I think there are two changes to do. First, ParsedHtmlDocument, or possibly ParsedDocument, should get a baseUrl property and a resolveUrl() method. Second HtmlImportScanner and friends need to use that.

@rictic jinx

I think we fixed this a bunch. Closing.

Was this page helpful?
0 / 5 - 0 ratings