From b2d6997eff8ebb8180ac98a01556adbc7801ed4d Mon Sep 17 00:00:00 2001 From: Hao-kang Den Date: Wed, 20 Mar 2013 16:39:36 +0800 Subject: [PATCH] encode unicode src, test added --- src/browser.coffee | 9 +++++---- test/test.html | 2 ++ 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/browser.coffee b/src/browser.coffee index fe07b4c0..2b3d8877 100644 --- a/src/browser.coffee +++ b/src/browser.coffee @@ -21,14 +21,15 @@ CoffeeScript.run = (code, options = {}) -> # If we're not in a browser environment, we're finished with the public API. return unless window? -# Include source maps where possible. If we've got a base64 encoder, and a -# JSON serializer, we're good to go. -if btoa? and JSON? +# Include source maps where possible. If we've got a base64 encoder, a +# JSON serializer, and tools for escaping unicode characters, we're good to go. +# Ported from https://developer.mozilla.org/en-US/docs/DOM/window.btoa +if btoa? and JSON? and unescape? and encodeURIComponent? compile = (code, options = {}) -> options.sourceMap = true options.inline = true {js, v3SourceMap} = CoffeeScript.compile code, options - "#{js}\n//@ sourceMappingURL=data:application/json;base64,#{btoa v3SourceMap}\n//@ sourceURL=coffeescript" + "#{js}\n//@ sourceMappingURL=data:application/json;base64,#{btoa unescape encodeURIComponent v3SourceMap}\n//@ sourceURL=coffeescript" # Load a remote script from the current domain via XHR. CoffeeScript.load = (url, callback, options = {}) -> diff --git a/test/test.html b/test/test.html index d5a568be..c12c4347 100644 --- a/test/test.html +++ b/test/test.html @@ -112,6 +112,8 @@ 'soaks' 'strings' ] + # allow utf-8 chars in comments + # 智に働けば角が立つ、情に掉させば流される。