From e4dd4f20566728f41e4d25e0c6d4e3a5e2b569ce Mon Sep 17 00:00:00 2001 From: Daniel Freedman Date: Tue, 19 Aug 2014 11:14:32 -0700 Subject: [PATCH] Always use uri encoded utf-8 Firefox and IE seem to base64 encode some extended ascii characters just fine, but decode breaks them. Fixes Polymer/polymer#717 --- src/Parser.js | 10 +-------- test/html/encoding.html | 28 ++++++++++++++++++++++++++ test/html/imports/encoding-import.html | 6 ++++++ test/js/tests.js | 1 + 4 files changed, 36 insertions(+), 9 deletions(-) create mode 100644 test/html/encoding.html create mode 100644 test/html/imports/encoding-import.html diff --git a/src/Parser.js b/src/Parser.js index f096fa5..2ad6d66 100644 --- a/src/Parser.js +++ b/src/Parser.js @@ -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) { diff --git a/test/html/encoding.html b/test/html/encoding.html new file mode 100644 index 0000000..e51ea46 --- /dev/null +++ b/test/html/encoding.html @@ -0,0 +1,28 @@ + + + + + + + + + + + + + + + diff --git a/test/html/imports/encoding-import.html b/test/html/imports/encoding-import.html new file mode 100644 index 0000000..d31686f --- /dev/null +++ b/test/html/imports/encoding-import.html @@ -0,0 +1,6 @@ + diff --git a/test/js/tests.js b/test/js/tests.js index 80346fe..507c67f 100644 --- a/test/js/tests.js +++ b/test/js/tests.js @@ -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'); });