From aaf39e70893c3a572f10603eb9c87b9c70c119ed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Petlu=C5=A1?= Date: Wed, 17 Aug 2016 19:38:47 +0200 Subject: [PATCH] Fix replace of captures and adjust tests --- index.js | 2 +- test/replace.js | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/index.js b/index.js index 33be4c2..8b0124a 100644 --- a/index.js +++ b/index.js @@ -102,7 +102,7 @@ function createReplaceFn(replace, isRegEx) { // And string parameters var paramLength = arguments.length - 2; for (var i = 1; i < paramLength; i++) { - newReplace = newReplace.replace('$' + i, arguments[i] || '') + newReplace = newReplace.replace(new RegExp('\\$' + i, 'g'), arguments[i] || '') } return newReplace; }; diff --git a/test/replace.js b/test/replace.js index ef3ab11..b5f4553 100644 --- a/test/replace.js +++ b/test/replace.js @@ -872,12 +872,12 @@ describe('replacestream', function () { }); it('should be able to replace captures using $1 notation', function (done) { - var replace = replaceStream(/(a)(b)/g, 'this is $1 and this is $2'); + var replace = replaceStream(/(a)(b)/g, 'this is $1 and this is $2 and this is again $1'); replace.pipe(concatStream({encoding: 'string'}, function(data) { var expected = [ - 'this is a and this is b', + 'this is a and this is b and this is again a', 'a', - 'this is a and this is b', + 'this is a and this is b and this is again a', 'b' ].join('\n');