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

Adding support for data uris in resolveUrl. #5199

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions lib/utils/resolve-url.html
Expand Up @@ -16,6 +16,7 @@

let CSS_URL_RX = /(url\()([^)]*)(\))/g;
let ABS_URL = /(^\/)|(^#)|(^[\w-\d]*:)/;
let DATA_URI = /data:/;
let workingURL;
let resolveDoc;
/**
Expand All @@ -31,6 +32,9 @@
* @return {string} resolved URL
*/
function resolveUrl(url, baseURI) {
if (baseURI && DATA_URI.test(baseURI)) {
return url;
}
if (url && ABS_URL.test(url)) {
return url;
}
Expand Down
3 changes: 2 additions & 1 deletion test/runner.html
Expand Up @@ -79,7 +79,8 @@
'unit/dir.html',
'unit/disable-upgrade.html',
'unit/shady-unscoped-style.html',
'unit/html-tag.html'
'unit/html-tag.html',
'unit/data-uri-link.html'
// 'unit/multi-style.html'
];

Expand Down
46 changes: 46 additions & 0 deletions test/unit/data-uri-link.html
@@ -0,0 +1,46 @@
<!doctype html>
<!--
@license
Copyright (c) 2017 The Polymer Project Authors. All rights reserved.
This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
Code distributed by Google as part of the polymer project is also
subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
-->
<html>
<head>
<script src="../../../webcomponentsjs/webcomponents-loader.js"></script>
<script src="../../../web-component-tester/browser.js"></script>
<link rel="import" href="../../polymer.html">
<link rel="import" href="data:text/html,%3Cdom-module%20id%3D%22element-data-uri%22%3E%3Cscript%3EPolymer(%7Bis%3A%22element-data-uri%22%2Cproperties%3A%7Bexists%3A%7Btype%3ABoolean%2Cvalue%3Atrue%7D%7D%7D)%3C%2Fscript%3E%3C%2Fdom-module%3E">
Copy link
Contributor

Choose a reason for hiding this comment

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

Would it be possible to put this into code with the URLencode? That would make the test more readable and understandable.

Copy link
Author

Choose a reason for hiding this comment

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

Possibly, yes. I can try at least :-)

Copy link
Author

Choose a reason for hiding this comment

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

Updated; PTAL.

Copy link
Author

Choose a reason for hiding this comment

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

Actually, what I attempted (visible here) works locally, but seems to timeout on tests on your travis environment. I'm not sure how to do this otherwise.

Copy link
Author

Choose a reason for hiding this comment

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

<!--
The above data uri will decode into the following HTML:

<dom-module id="element-data-uri">
<script>
Polymer({
is: "element-data-uri",
properties: {
exists: {
type: Boolean,
value: true
}
}
});
</script>
</dom-module>
-->

</head>
<body>
<element-data-uri id="fixture"></element-data-uri>
<script>
suite('Link import with a data uri', function() {
test('imported', function() {
assert.isTrue(document.getElementById('fixture').exists);
});
});
</script>
</body>
</html>
7 changes: 7 additions & 0 deletions test/unit/resolveurl.html
Expand Up @@ -143,6 +143,13 @@
assert.equal(actual, expected);
});

test('resolveUrl api with data base', function() {
var el = document.createElement('p-r');
var expected = 'resolveurl.html';
var actual = el.resolveUrl('resolveurl.html', 'data:text/html,some%20data');
assert.equal(actual, expected);
});

test('resolveUrl api, when defined in main doc', function() {
var el = document.querySelector('x-resolve');
var expected = document.location.href.replace(/[?#].*$/, '');
Expand Down