Skip to content

Commit

Permalink
Merge pull request #27 from martinpetlus/fix-replace-of-captures
Browse files Browse the repository at this point in the history
Fix replace of captures
  • Loading branch information
mehtaphysical committed Aug 20, 2016
2 parents 7f9bd19 + aaf39e7 commit 807e7e0
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
Expand Down
6 changes: 3 additions & 3 deletions test/replace.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand Down

0 comments on commit 807e7e0

Please sign in to comment.