diff --git a/lib/execjs/external_runtime.rb b/lib/execjs/external_runtime.rb index 2f35cd6..78c517c 100644 --- a/lib/execjs/external_runtime.rb +++ b/lib/execjs/external_runtime.rb @@ -37,7 +37,9 @@ module ExecJS def compile(source) @runtime.send(:runner_source).dup.tap do |output| - output.sub!('#{source}', source) + output.sub!('#{source}') do + source + end output.sub!('#{json2_source}') do IO.read(ExecJS.root + "/support/json2.js") end diff --git a/test/test_runtimes.rb b/test/test_runtimes.rb index e45eccc..5d7d90c 100644 --- a/test/test_runtimes.rb +++ b/test/test_runtimes.rb @@ -14,6 +14,7 @@ module TestRuntime assert_equal "hello", @runtime.exec("return 'hello'") assert_equal({"a"=>1,"b"=>2}, @runtime.exec("return {a:1,b:2}")) assert_equal "café", @runtime.exec("return 'café'") + assert_equal "\\", @runtime.exec('return "\\\\"') end def test_eval @@ -27,6 +28,7 @@ module TestRuntime assert_equal "hello", @runtime.eval("'hello'") assert_equal({"a"=>1,"b"=>2}, @runtime.eval("{a:1,b:2}")) assert_equal "café", @runtime.eval("'café'") + assert_equal "\\", @runtime.eval('"\\\\"') end def test_compile