Skip to content

Commit

Permalink
v1.4.2
Browse files Browse the repository at this point in the history
Fix line regex creation
  • Loading branch information
eliottvincent committed May 23, 2023
1 parent 07e9c73 commit f19364f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
18 changes: 12 additions & 6 deletions lib/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -574,28 +574,30 @@ class Parser {
this.__regexes[_key_line] = [];

for (var _i = 0; _i < _entry.length; _i++) {
var _regex_original = new RE2(_entry[_i]);
var _regex = _entry[_i];

// Build 'line' alternative?
if (LINE_REGEXES.includes(_key)) {
var _regex_line = this.__buildLineRegex(_regex_original);
var _regex_line = this.__buildLineRegex(_regex);

this.__regexes[_key_line].push(_regex_line);
}

this.__regexes[_key].push(_regex_original);
this.__regexes[_key].push(
new RE2(_regex)
);
}
} else {
var _regex_original = new RE2(_entry);
var _regex = _entry;

// Build 'line' alternative?
if (LINE_REGEXES.includes(_key)) {
var _regex_line = this.__buildLineRegex(_regex_original);
var _regex_line = this.__buildLineRegex(_regex);

this.__regexes[_key_line] = _regex_line;
}

this.__regexes[_key] = _regex_original;
this.__regexes[_key] = new RE2(_regex);
}
}
}
Expand All @@ -610,6 +612,10 @@ class Parser {
__buildLineRegex(regex) {
// A 'line' regex will capture not only inner groups, but also the line \
// itself
// Important: `regex` must be a raw regular expression literal, not an RE2 \
// instance. It seems that under some inexplicable circumstances, \
// the RE2 instance sometimes doesn't have its `source` and `flags` \
// properties correctly populated.
var _source = `(${regex.source})`;
var _flags = regex.flags;

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "email-forward-parser",
"version": "1.4.1",
"version": "1.4.2",
"description": "Parses forwarded emails and extract content",
"author": "Eliott Vincent <eliott@crisp.chat>",
"main": "lib/index.js",
Expand Down

0 comments on commit f19364f

Please sign in to comment.