Skip to content

Commit

Permalink
Fix negative PCRE flags in heuristics causing crash
Browse files Browse the repository at this point in the history
  • Loading branch information
Nixinova committed Jun 25, 2023
1 parent 8220770 commit 21f1a4b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
3 changes: 3 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Changelog

## Next
- Fixed a crash occurring when parsing heuristics with negative inline PCRE flags.

## 2.5.4
*2023-01-11*
- Fixed gitattributes wildcards not being applied into subfolders.
Expand Down
9 changes: 5 additions & 4 deletions src/helpers/convert-pcre.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@ export default function pcre(regex: string): RegExp {
const replace = (search: string | RegExp, replace: string) => finalRegex = finalRegex.replace(search, replace);
const finalFlags = new Set<string>();
// Convert inline flag declarations
const inlineMatches = regex.matchAll(/\?([a-z]):/g);
const startMatches = regex.matchAll(/\(\?([a-z]+)\)/g);
for (const [match, flags] of [...inlineMatches, ...startMatches]) {
const inlineMatches = regex.matchAll(/\?(-)?([a-z]):/g);
const startMatches = regex.matchAll(/\(\?(-)?([a-z]+)\)/g);
for (const [match, isNegative, flags] of [...inlineMatches, ...startMatches]) {
replace(match, '');
[...flags].forEach(flag => finalFlags.add(flag));
const func = (flag: string) => isNegative ? finalFlags.delete(flag) : finalFlags.add(flag);
[...flags].forEach(func);
}
// Remove PCRE-only syntax
replace(/([*+]){2}/g, '$1');
Expand Down

0 comments on commit 21f1a4b

Please sign in to comment.