diff --git a/index.js b/index.js index ebf8fb0..25c99c3 100644 --- a/index.js +++ b/index.js @@ -77,7 +77,7 @@ module.exports = function (file) { var fpath = Function(vars, t)(file, dirname); var enc = 'utf8'; - if (!/^Function/.test(args[1]) && args[2]) { + if (args[1] && !/^Function/.test(args[1].type)) { enc = Function('return ' + unparse(args[1]))() } diff --git a/test/encoding.js b/test/encoding.js new file mode 100644 index 0000000..e632d72 --- /dev/null +++ b/test/encoding.js @@ -0,0 +1,19 @@ +var test = require('tap').test; +var browserify = require('browserify'); + +var vm = require('vm'); +var path = require('path'); + +test('sync string encoding', function (t) { + t.plan(1); + var b = browserify(__dirname + '/files/encoding.js'); + b.transform(path.dirname(__dirname)); + b.bundle(function (err, src) { + if (err) t.fail(err); + vm.runInNewContext(src, { + setTimeout: setTimeout, + console: { log: log } + }); + }); + function log (msg) { t.equal(msg, '3c623e6265657020626f6f703c2f623e0a') } +}); diff --git a/test/files/encoding.js b/test/files/encoding.js new file mode 100644 index 0000000..b34627d --- /dev/null +++ b/test/files/encoding.js @@ -0,0 +1,4 @@ +var fs = require('fs'); +var txt = fs.readFileSync(__dirname + '/robot.html', { encoding: 'hex' }); + +console.log(txt); \ No newline at end of file