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

Commit

Permalink
Merge pull request #73 from Polymer/remove-base64
Browse files Browse the repository at this point in the history
Always use uri encoded utf-8
  • Loading branch information
dfreedm committed Aug 19, 2014
2 parents 3bfcb96 + e4dd4f2 commit 9a4ba20
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 9 deletions.
10 changes: 1 addition & 9 deletions src/Parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -257,15 +257,7 @@ function nodeIsImport(elt) {

function generateScriptDataUrl(script) {
var scriptContent = generateScriptContent(script);
var b64 = 'data:text/javascript';
// base64 may be smaller, but does not handle unicode characters
// attempt base64 first, fall back to escaped text
try {
b64 += (';base64,' + btoa(scriptContent));
} catch(e) {
b64 += (';charset=utf-8,' + encodeURIComponent(scriptContent));
}
return b64;
return 'data:text/javascript;charset=utf-8,' + encodeURIComponent(scriptContent);
}

function generateScriptContent(script) {
Expand Down
28 changes: 28 additions & 0 deletions test/html/encoding.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title></title>
<script src="../../../tools/test/htmltest.js"></script>
<script src="../../../tools/test/chai/chai.js"></script>
<script src="../../html-imports.js"></script>
<link rel="import" href="imports/encoding-import.html">
</head>
<body>
<span></span>
<script>
function test() {
run();
var span = document.querySelector('span');
chai.assert.equal(span.textContent, 'Róbert Viðar Bjarnason');
done();
}

if (HTMLImports.ready) {
test();
} else {
addEventListener('HTMLImportsLoaded', test);
}
</script>
</body>
</html>
6 changes: 6 additions & 0 deletions test/html/imports/encoding-import.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<script>
function run() {
var span = document.querySelector('span');
span.textContent = 'Róbert Viðar Bjarnason';
};
</script>
1 change: 1 addition & 0 deletions test/js/tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@ htmlSuite('HTMLImports', function() {
// TODO(sjmiles): feature not implemented currently
//htmlTest('html/dynamic-elements.html');
htmlTest('html/csp.html');
htmlTest('html/encoding.html');
});

0 comments on commit 9a4ba20

Please sign in to comment.