ractivejs / rvc

RequireJS loader plugin for Ractive components
20 stars 10 forks source link

Breaking on unencodable strings #14

Closed fskreuz closed 9 years ago

fskreuz commented 9 years ago

So one of our non-technical team decides to join the fun and write code (or at least change our terrible english). Then we hit a snag. This section breaks when it encounters non-latin characters caused by using "non-geeky editor". The "bent single quote" and "extended dash", which some editors use in place of the regular single quote and dash will break the code.

    if (options.sourceMap) {
        script += "\n//# sourceMa" + "ppingURL=data:application/json;charset=utf-8;base64," + base64Encode(JSON.stringify(options.sourceMap));
    } else if (options.sourceURL) {
        script += "\n//# sourceURL=" + options.sourceURL;
    }

The error thrown is:

message: "Failed to execute 'btoa' on 'Window': The string to be encoded contains characters outside of the Latin1 range."

Here's the twist: It doesn't seem to happen to v0.6.x,

Did a bit of research, this might help: https://developer.mozilla.org/en-US/docs/Web/API/WindowBase64/btoa

SiZapPaaiGwat commented 9 years ago

I got this problem when i added some comment contain chinese. And I finally got the reason why this error comes out. see this PR: https://github.com/ractivejs/rvc/pull/16

Rich-Harris commented 9 years ago

@fskreuz sorry, I haven't been paying much attention to this repo... this should be fixed in 0.4.0 thanks to @simongfxu, if it's still an issue four months later. Will close