Skip to content

Commit

Permalink
misc: add anti timestamp rule for auto match (#673)
Browse files Browse the repository at this point in the history
and also add another part to the logic so we can control
when we want to break or continue the loop auto match logic loop.

Co-authored-by: ElementalCrisis <[email protected]>
  • Loading branch information
revam and ElementalCrisis authored Nov 11, 2023
1 parent 106db77 commit 21c89a1
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/core/utilities/auto-match-logic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export type PathMatchRule = {
match: RegExpExecArray,
parentMatch: RegExpExecArray | null,
grandparentMatch: RegExpExecArray | null,
): PathDetails | null;
): PathDetails | null | false;
defaults?: Partial<PathDetails>;
};

Expand Down Expand Up @@ -139,10 +139,16 @@ export function detectShow(filePath: string | undefined | null): PathDetails | n
const finalDetails = transform(initialDetails, match, parentMatch, grandParentMatch);

// Since the transformer also can return null (to invalidte the match)
// then we need to check if the transformed details before returning.
// then we need to check the transformed details before returning.
if (finalDetails) {
return finalDetails;
}

// Break the loop if we receive `null`, continue the loop if we receive
// `false`.
if (finalDetails === null) {
break;
}
}
}
return null;
Expand Down
7 changes: 7 additions & 0 deletions src/core/utilities/auto-match-regexes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,13 @@ try {
};

PathMatchRuleSet.push(
{
name: 'anti-timestamp',
regex:
/^\d{4}[._:\- ]\d{2}[._:\- ]\d{2}[._:\- T]\d{2}[._:\- ]\d{2}[._:\- ]\d{2}(?:[._:\- ]\d{1,6})?(?:Z|[+-]\d{2}:?\d{2})?\.(?<extension>[a-zA-Z0-9_\-+]+)$/id,
// invalidate the match.
transform: () => null,
},
{
name: 'default',
regex:
Expand Down

0 comments on commit 21c89a1

Please sign in to comment.