kesla / async-replace

Run replace on a string and update it asynchronous
18 stars 6 forks source link

Exception when no string matches found #1

Closed tornillo closed 11 years ago

tornillo commented 11 years ago
With global property:
asyncReplace("aaa", /(\d)/g, function(){}, function(){})

/tmp/node-test/node_modules/async-replace/async-replace.js:36
    while(matched.length > 0) {
                 ^
TypeError: Cannot read property 'length' of null
    at module.exports (/tmp/node-test/node_modules/async-replace/async-replace.js:36:18)
Without global property:
asyncReplace("aaa", /(\d)/, function(){}, function(){})

/tmp/node-test/node_modules/async-replace/async-replace.js:13
    var args = matched.slice();
                       ^
TypeError: Cannot call method 'slice' of null
    at replaceLocal (/tmp/node-test/node_modules/async-replace/async-replace.js:13:24)

To fix this errors please add this code after "var matched = string.match(regexp);" strings in source:

if (!matched) return callback(null, string);

It will return not modified source string to callback function.

Thanks!

kesla commented 11 years ago

Thanks for input, published as part of 0.0.2