Skip to content
This repository has been archived by the owner on Jun 12, 2019. It is now read-only.

Commit

Permalink
bugfix: respecting $ special meaning in string replace.
Browse files Browse the repository at this point in the history
  • Loading branch information
Dante committed Aug 5, 2015
1 parent 8d2aa5a commit 4645f75
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

var proxyLoader = function(source)
{
if (this && this.cacheable) this.cacheable();
var extract = /(require\s*\()['"]?([^\)'"]*)['"]?(\))/g;

var cache = {};
Expand Down Expand Up @@ -96,7 +97,7 @@ var proxyLoader = function(source)
}

// Grab the injection block's source and implant the module's source
var injectorBlock = injector.toString().replace('__INJECTION_POINT__', source);
var injectorBlock = injector.toString().split('__INJECTION_POINT__').join(source);

results.push(injectorBlock);

Expand Down
10 changes: 10 additions & 0 deletions test/proxy-loader.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,15 @@ describe('proxy-loader', function()
});
});

describe('Bugs', function()
{
// Old code has string.replace which has special characters
it('should not break when the srouce code has $ characters', function(done)
{
done();
});
});

// Test strings
var validCommonJs = '\'use strict\'' +
'var x = require(\'module\'),' +
Expand All @@ -80,6 +89,7 @@ describe('proxy-loader', function()
' map: require(\'lodash/map\')' +
' delay: require(\'lodash/delay\')' +
'}' +
'var valid = \'string($\' + 500 + \')\';' +
'module.exports = \'string\'';

var validAMD = '\'use strict\'' +
Expand Down

0 comments on commit 4645f75

Please sign in to comment.