Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
this.emitter = new Emitter()
this.repository = null
this.initialRule = null
this.rawPatterns = patterns
this.rawRepository = repository
if (injectionSelector) {
this.injectionSelector = new ScopeSelector(injectionSelector)
} else {
this.injectionSelector = null
}
if (firstLineMatch) {
this.firstLineRegex = new OnigRegExp(firstLineMatch)
} else {
this.firstLineRegex = null
}
if (!this.fileTypes) { this.fileTypes = [] }
this.includedGrammarScopes = []
// Create last since Injections uses APIs from this class
this.injections = new Injections(this, injections)
}
FilterGrok.prototype.expandGrokPattern = function(regex, extra_patterns) {
var offset = 0;
var reduced = regex;
var result;
var grokFinder = new OnigRegExp('%{[^}]+}');
var grokParts = new RegExp('%{([^:]+):?(.*)}');
while ((result = grokFinder.searchSync(regex, offset))) {
offset = result[0].end;
var grokExp = result[0].match;
var parts = grokExp.match(grokParts);
var p = global_patterns[parts[1]] || extra_patterns[parts[1]];
if (p) {
if (parts[2].length > 0) {
this.fields.push(parts[2]);
}
var reg = this.expandGrokPattern(p, extra_patterns);
if (parts[2].length > 0) {
// create a named capturing group
reg = '(?<' + parts[2] + '>' + reg + ')';
pattern => new oniguruma.OnigRegExp(pattern)
);
t.parseSync = function(str) {
if (!t.regexp) {
t.regexp = new OnigRegExp(t.resolved);
}
var result = t.regexp.searchSync(str);
if(!result)
return null;
var r = {};
result.forEach(function(item, index) {
var field = t.fields[index];
if(field && item.match) {
r[field] = item.match;
}
});
regexForPattern(pattern) {
if (pattern) {
if (!this.regexesByPattern[pattern]) {
this.regexesByPattern[pattern] = new OnigRegExp(pattern);
}
return this.regexesByPattern[pattern];
}
}
var _done = function(extra_patterns) {
try {
var expanded = this.expandGrokPattern(this.grok, extra_patterns);
this.regex = new OnigRegExp(expanded);
}
catch(e) {
logger.error('Unable to process grok pattern', this.grok, e);
return callback(e);
}
callback();
}.bind(this);
t.parse = function(str, next) {
if (!t.regexp) {
t.regexp = new OnigRegExp(t.resolved);
}
t.regexp.search(str, function(err, result) {
if(err || !result)
return next(err, result);
var r = {};
result.forEach(function(item, index) {
var field = t.fields[index];
if(field && item.match) {
r[field] = item.match;
}
});
return next(err, r, result);