Skip to content

Commit a7baa93

Browse files
authored
feat(parser): ignore white space in pom.xml files (#7747)
Signed-off-by: Samuel Gaist <samuel.gaist@idiap.ch>
1 parent 922949a commit a7baa93

File tree

3 files changed

+96
-1
lines changed

3 files changed

+96
-1
lines changed

pkg/dependency/parser/java/pom/artifact.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ func evaluateVariable(s string, props map[string]string, seenProps []string) str
163163
}
164164
s = strings.ReplaceAll(s, m[0], newValue)
165165
}
166-
return s
166+
return strings.TrimSpace(s)
167167
}
168168

169169
func printLoopedPropertiesStack(env string, usedProps []string) {

pkg/dependency/parser/java/pom/parse_test.go

+64
Original file line numberDiff line numberDiff line change
@@ -1974,6 +1974,70 @@ func TestPom_Parse(t *testing.T) {
19741974
},
19751975
},
19761976
},
1977+
//[INFO] com.example:root-pom-with-spaces:jar:1.0.0
1978+
//[INFO] \- org.example:example-nested:jar:3.3.3:compile
1979+
//[INFO] \- org.example:example-dependency:jar:1.2.4:compile
1980+
//[INFO] \- org.example:example-api:jar:2.0.0:compile
1981+
{
1982+
name: "space at the start and/or end of the text nodes",
1983+
inputFile: filepath.Join("testdata", "with-spaces", "pom.xml"),
1984+
local: true,
1985+
want: []ftypes.Package{
1986+
{
1987+
ID: "com.example:root-pom-with-spaces:1.0.0",
1988+
Name: "com.example:root-pom-with-spaces",
1989+
Version: "1.0.0",
1990+
Relationship: ftypes.RelationshipRoot,
1991+
},
1992+
{
1993+
ID: "org.example:example-nested:3.3.3",
1994+
Name: "org.example:example-nested",
1995+
Version: "3.3.3",
1996+
Relationship: ftypes.RelationshipDirect,
1997+
Locations: ftypes.Locations{
1998+
{
1999+
StartLine: 24,
2000+
EndLine: 28,
2001+
},
2002+
},
2003+
},
2004+
{
2005+
ID: "org.example:example-api:2.0.0",
2006+
Name: "org.example:example-api",
2007+
Version: "2.0.0",
2008+
Licenses: []string{"The Apache Software License, Version 2.0"},
2009+
Relationship: ftypes.RelationshipIndirect,
2010+
},
2011+
// dependency version is taken from `com.example:root-pom-with-spaces` from dependencyManagement
2012+
// not from `com.example:example-nested` from `com.example:example-nested`
2013+
{
2014+
ID: "org.example:example-dependency:1.2.4",
2015+
Name: "org.example:example-dependency",
2016+
Version: "1.2.4",
2017+
Relationship: ftypes.RelationshipIndirect,
2018+
},
2019+
},
2020+
wantDeps: []ftypes.Dependency{
2021+
{
2022+
ID: "com.example:root-pom-with-spaces:1.0.0",
2023+
DependsOn: []string{
2024+
"org.example:example-nested:3.3.3",
2025+
},
2026+
},
2027+
{
2028+
ID: "org.example:example-dependency:1.2.4",
2029+
DependsOn: []string{
2030+
"org.example:example-api:2.0.0",
2031+
},
2032+
},
2033+
{
2034+
ID: "org.example:example-nested:3.3.3",
2035+
DependsOn: []string{
2036+
"org.example:example-dependency:1.2.4",
2037+
},
2038+
},
2039+
},
2040+
},
19772041
}
19782042
for _, tt := range tests {
19792043
t.Run(tt.name, func(t *testing.T) {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
3+
<modelVersion> 4.0.0</modelVersion>
4+
5+
<groupId>com.example </groupId>
6+
<artifactId> root-pom-with-spaces </artifactId>
7+
<version> 1.0.0</version>
8+
9+
<properties>
10+
<dependency.version > 1.2.4</dependency.version >
11+
</properties>
12+
13+
<dependencyManagement>
14+
<dependencies>
15+
<dependency>
16+
<groupId> org.example</groupId>
17+
<artifactId>example-dependency </artifactId>
18+
<version>${dependency.version} </version>
19+
</dependency>
20+
</dependencies>
21+
</dependencyManagement>
22+
23+
<dependencies>
24+
<dependency>
25+
<groupId> org.example </groupId>
26+
<artifactId> example-nested </artifactId>
27+
<version> 3.3.3 </version>
28+
</dependency>
29+
</dependencies>
30+
31+
</project>

0 commit comments

Comments
 (0)