Skip to content

Commit

Permalink
optimize regular expression creation in NpmComponentDetector (#1177)
Browse files Browse the repository at this point in the history
* optimize regular expression creation in NpmComponentDetector

* optimize regular expression creation in NpmComponentDetector

* Update src/Microsoft.ComponentDetection.Detectors/npm/NpmComponentDetector.cs

Co-authored-by: Coby Allred <[email protected]>

---------

Co-authored-by: Coby Allred <[email protected]>
  • Loading branch information
Meir017 and cobya authored Jun 19, 2024
1 parent 155b742 commit dafe527
Showing 1 changed file with 3 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ namespace Microsoft.ComponentDetection.Detectors.Npm;

public class NpmComponentDetector : FileComponentDetector
{
private static readonly Regex SingleAuthor = new Regex(@"^(?<name>([^<(]+?)?)[ \t]*(?:<(?<email>([^>(]+?))>)?[ \t]*(?:\(([^)]+?)\)|$)", RegexOptions.Compiled);

public NpmComponentDetector(
IComponentStreamEnumerableFactory componentStreamEnumerableFactory,
IObservableDirectoryWalkerFactory walkerFactory,
Expand Down Expand Up @@ -114,9 +116,7 @@ private NpmAuthor GetAuthor(JToken authorToken, string packageName, string fileP

string authorName;
string authorEmail;
var authorSingleStringPattern = @"^(?<name>([^<(]+?)?)[ \t]*(?:<(?<email>([^>(]+?))>)?[ \t]*(?:\(([^)]+?)\)|$)";
var authorMatch = new Regex(authorSingleStringPattern).Match(authorString);

var authorMatch = SingleAuthor.Match(authorString);
/*
* for parsing author in Json Format
* for e.g.
Expand Down

0 comments on commit dafe527

Please sign in to comment.