Fatal Bug in the function interpolate (cannot work with '$') #33

Closed
dai-shi opened this Issue Jan 3, 2013 · 0 comments

Comments

2 participants

dai-shi commented Jan 3, 2013

If you have for example console.log('$') in a benchmark code, it fails to run the benchmark suite.
cf. https://developer.mozilla.org/en/docs/JavaScript/Reference/Global_Objects/String/replace

To fix this, apply the following patch. Thanks.

--- benchmark.js.bak    2013-01-03 13:06:16.739109681 +0900
+++ benchmark.js        2013-01-03 15:06:32.846285741 +0900
@@ -1630,7 +1630,7 @@
   function interpolate(string, object) {
     forOwn(object, function(value, key) {
       // escape regexp special characters in `key`
-      string = string.replace(RegExp('#\\{' + key.replace(/([.*+?^=!:${}()|[\]\/\\])/g, '\\$1') + '\\}', 'g'), value);
+      string = string.replace(RegExp('#\\{' + key.replace(/([.*+?^=!:${}()|[\]\/\\])/g, '\\$1') + '\\}', 'g'), value.replace(/\$/g, '$$$$'));
     });
     return string;
   }

@jdalton jdalton closed this in a838e23 Jan 3, 2013

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment