From 66c86a6689aaac82006fa47762bd86496ad76bf7 Mon Sep 17 00:00:00 2001 From: Vojta Jina Date: Fri, 29 Nov 2013 13:26:12 -0800 Subject: [PATCH] fix(config): ignore empty string patterns An empty string pattern is a mistake - there is no reason to do that. It can however happen (for instance when you generate the config file). Before this fix, Karma would try to watch this empty string pattern, which would result in watching the entire `basePath` directory. Now, the pattern will be ignored and a warning showed. --- lib/config.js | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/lib/config.js b/lib/config.js index 17b6fe037..897a5bc74 100644 --- a/lib/config.js +++ b/lib/config.js @@ -23,18 +23,19 @@ var UrlPattern = function(url) { var createPatternObject = function(pattern) { - if (helper.isString(pattern)) { + if (pattern && helper.isString(pattern)) { return helper.isUrlAbsolute(pattern) ? new UrlPattern(pattern) : new Pattern(pattern); } if (helper.isObject(pattern)) { - if (!helper.isDefined(pattern.pattern)) { - log.warn('Invalid pattern %s!\n\tObject is missing "pattern" property".', pattern); - } - - return helper.isUrlAbsolute(pattern.pattern) ? + if (pattern.pattern && helper.isString(pattern.pattern)) { + return helper.isUrlAbsolute(pattern.pattern) ? new UrlPattern(pattern.pattern) : new Pattern(pattern.pattern, pattern.served, pattern.included, pattern.watched); + } + + log.warn('Invalid pattern %s!\n\tObject is missing "pattern" property.', pattern); + return new Pattern(null, false, false, false); } log.warn('Invalid pattern %s!\n\tExpected string or object with "pattern" property.', pattern);