@@ -18,6 +18,8 @@ import (
1818 "strings"
1919)
2020
21+ // VersionForMainModule - We don't have information in cocoapods on the current package, or main module, we only have information on its
22+ // dependencies.
2123const (
2224 VersionForMainModule = "0.0.0"
2325)
@@ -45,39 +47,46 @@ func GetTechDependencyLocation(directDependencyName, directDependencyVersion str
4547 foundDependency := false
4648 var tempIndex int
4749 for i , line := range lines {
48- if strings .Contains (line , directDependencyName ) {
49- startLine = i
50- startCol = strings .Index (line , directDependencyName )
51- foundDependency = true
52- tempIndex = i
53- }
54- // This means we are in a new dependency (we cannot find dependency name and version together)
55- if i > tempIndex && foundDependency && strings .Contains (line , "pod" ) {
56- foundDependency = false
57- } else if foundDependency && strings .Contains (line , directDependencyVersion ) {
58- endLine = i
59- endCol = len (line )
60- var snippet string
61- if endLine == startLine {
62- snippet = lines [startLine ][startCol :endCol ]
63- } else {
64- for snippetLine := 1 ; snippetLine < endLine - startLine + 1 ; snippetLine ++ {
65- switch snippetLine {
66- case 0 :
67- snippet += "\n " + lines [snippetLine ][startLine :]
68- case endLine - startLine :
69- snippet += "\n " + lines [snippetLine ][:endCol ]
70- default :
71- snippet += "\n " + lines [snippetLine ]
72- }
73- }
50+ foundDependency , tempIndex , startLine , startCol = parsePodLine (line , directDependencyName , directDependencyVersion , descriptorPath , i , tempIndex , startLine , startCol , endLine , endCol , lines , foundDependency , & podPositions )
51+ }
52+ }
53+ return podPositions , nil
54+ }
55+
56+ func parsePodLine (line , directDependencyName , directDependencyVersion , descriptorPath string , i , tempIndex , startLine , startCol , endLine , endCol int , lines []string , foundDependency bool , podPositions * []* sarif.Location ) (bool , int , int , int ) {
57+ if strings .Contains (line , directDependencyName ) {
58+ startLine = i
59+ startCol = strings .Index (line , directDependencyName )
60+ foundDependency = true
61+ tempIndex = i
62+ }
63+ // This means we are in a new dependency (we cannot find dependency name and version together)
64+ if i > tempIndex && foundDependency && strings .Contains (line , "pod" ) {
65+ foundDependency = false
66+ } else if foundDependency && strings .Contains (line , directDependencyVersion ) {
67+ endLine = i
68+ endCol = len (line )
69+ var snippet string
70+ // if the tech dependency is a one-liner
71+ if endLine == startLine {
72+ snippet = lines [startLine ][startCol :endCol ]
73+ // else it is more than one line, so we need to parse all lines
74+ } else {
75+ for snippetLine := 0 ; snippetLine < endLine - startLine + 1 ; snippetLine ++ {
76+ switch snippetLine {
77+ case 0 :
78+ snippet += "\n " + lines [snippetLine ][startLine :]
79+ case endLine - startLine :
80+ snippet += "\n " + lines [snippetLine ][:endCol ]
81+ default :
82+ snippet += "\n " + lines [snippetLine ]
7483 }
75- podPositions = append (podPositions , sarifutils .CreateLocation (descriptorPath , startLine , endLine , startCol , endCol , snippet ))
76- foundDependency = false
7784 }
7885 }
86+ * podPositions = append (* podPositions , sarifutils .CreateLocation (descriptorPath , startLine , endLine , startCol , endCol , snippet ))
87+ foundDependency = false
7988 }
80- return podPositions , nil
89+ return foundDependency , tempIndex , startLine , startCol
8190}
8291
8392func FixTechDependency (dependencyName , dependencyVersion , fixVersion string , descriptorPaths ... string ) error {
0 commit comments