Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fixes #6 - String#replace avoid special replacement strings

For example:
$$ -> $
$& -> the matched substring

see https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/String/replace#Specifying_a_string_as_a_parameter

Simply using a function as second parameter will prevent replacing special characters
  • Loading branch information...
commit 4f308e8389639763b9bf23b6d511d49037381db9 1 parent ba88c86
@arian arian authored
Showing with 3 additions and 1 deletion.
  1. +3 −1 lib/wrapup.js
View
4 lib/wrapup.js
@@ -25,7 +25,9 @@ var prime = require("prime/prime"),
// util methods
var replaces = function(str, obj){
- for (var key in obj) str = str.replace(new RegExp("@" + key, "g"), obj[key])
+ for (var key in obj) str = str.replace(new RegExp("@" + key, "g"), function(){
+ return obj[key]
+ })
return str
}
Please sign in to comment.
Something went wrong with that request. Please try again.