diff --git a/librarydetection/languages/Java.go b/librarydetection/languages/Java.go index 37f8f41..6bef38e 100644 --- a/librarydetection/languages/Java.go +++ b/librarydetection/languages/Java.go @@ -16,10 +16,19 @@ type javaAnalyzer struct{} func (a *javaAnalyzer) ExtractLibraries(contents string) ([]string, error) { // regex to find imports like org.springframework (excluding standart java libraries) regex1, err := regexp.Compile(`import ([^java][a-zA-Z0-9]*\.[a-zA-Z0-9]*)`) + if err != nil { + return nil, err + } // regex to find imports like org.springframework.boot regex2, err := regexp.Compile(`import ([^java][a-zA-Z0-9]*\.[a-zA-Z0-9]*\.[a-zA-Z0-9]*)`) + if err != nil { + return nil, err + } // regex to find static imports like org.springframework (excluding standart java libraries) regex3, err := regexp.Compile(`import static ([^java][a-zA-Z0-9]*\.[a-zA-Z0-9]*)`) + if err != nil { + return nil, err + } // regex to find static imports like org.springframework.boot regex4, err := regexp.Compile(`import static ([^java][a-zA-Z0-9]*\.[a-zA-Z0-9]*\.[a-zA-Z0-9]*)`) if err != nil { diff --git a/librarydetection/languages/JavaScript.go b/librarydetection/languages/JavaScript.go index e1b3812..8d51109 100644 --- a/librarydetection/languages/JavaScript.go +++ b/librarydetection/languages/JavaScript.go @@ -14,7 +14,12 @@ func NewJavaScriptAnalyzer() librarydetection.Analyzer { type javaScriptAnalyzer struct{} func (a *javaScriptAnalyzer) ExtractLibraries(contents string) ([]string, error) { + require, err := regexp.Compile(`require\(["\'](.+)["\']\);?\s`) + if err != nil { + return nil, err + } + importRegex, err := regexp.Compile(`import\s*(?:.+ from)?\s?\(?[\'"](.+)[\'"]\)?;?\s`) if err != nil { return nil, err diff --git a/librarydetection/languages/Python.go b/librarydetection/languages/Python.go index 97c39fc..90a73b9 100644 --- a/librarydetection/languages/Python.go +++ b/librarydetection/languages/Python.go @@ -15,6 +15,9 @@ type pythonScriptAnalyzer struct{} func (a *pythonScriptAnalyzer) ExtractLibraries(contents string) ([]string, error) { fromRegex, err := regexp.Compile(`from (.+) import`) + if err != nil { + return nil, err + } importRegex, err := regexp.Compile(`import ([a-zA-Z0-9_-]+)(?:\s| as)`) if err != nil { return nil, err diff --git a/librarydetection/languages/TypeScript.go b/librarydetection/languages/TypeScript.go index f37cb79..8d58455 100644 --- a/librarydetection/languages/TypeScript.go +++ b/librarydetection/languages/TypeScript.go @@ -15,6 +15,9 @@ type typeScriptAnalyzer struct{} func (a *typeScriptAnalyzer) ExtractLibraries(contents string) ([]string, error) { require, err := regexp.Compile(`require\(["\'](.+)["\']\);?\s`) + if err != nil { + return nil, err + } importRegex, err := regexp.Compile(`import\s*(?:.+ from)?\s?\(?[\'"](.+)[\'"]\)?;?\s`) if err != nil { return nil, err