File tree Expand file tree Collapse file tree
dd-java-agent/agent-ci-visibility/src
main/java/datadog/trace/civisibility/ci
test/groovy/datadog/trace/civisibility/ci
internal-api/src/main/java/datadog/trace/api/git Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -170,7 +170,7 @@ public CIInfo(
170170 this .ciPipelineNumber = ciPipelineNumber ;
171171 this .ciPipelineUrl = ciPipelineUrl ;
172172 this .ciJobUrl = ciJobUrl ;
173- this .ciWorkspace = ciWorkspace ;
173+ this .ciWorkspace = sanitizeWorkspace ( ciWorkspace ) ;
174174 this .ciNodeName = ciNodeName ;
175175 this .ciNodeLabels = ciNodeLabels ;
176176 this .ciEnvVars = ciEnvVars ;
@@ -209,14 +209,20 @@ public String getCiJobUrl() {
209209 return ciJobUrl ;
210210 }
211211
212- /** @return Workspace path without the trailing separator */
213- public String getCiWorkspace () {
214- String realCiWorkspace = FileUtils .toRealPath (ciWorkspace );
215- return (realCiWorkspace == null || !realCiWorkspace .endsWith (File .separator ))
212+ private String sanitizeWorkspace (String workspace ) {
213+ String realCiWorkspace = FileUtils .toRealPath (workspace );
214+ return (realCiWorkspace == null
215+ || !realCiWorkspace .endsWith (File .separator )
216+ || realCiWorkspace .length () == 1 ) // root path "/"
216217 ? realCiWorkspace
217218 : (realCiWorkspace .substring (0 , realCiWorkspace .length () - 1 ));
218219 }
219220
221+ /** @return Workspace path without the trailing separator */
222+ public String getCiWorkspace () {
223+ return ciWorkspace ;
224+ }
225+
220226 public String getCiNodeName () {
221227 return ciNodeName ;
222228 }
Original file line number Diff line number Diff line change 1+ package datadog.trace.civisibility.ci
2+
3+
4+ import spock.lang.Specification
5+
6+ class CIInfoTest extends Specification {
7+
8+ def " test ci workspace is correctly sanitized #iterationIndex" () {
9+ def builder = CIInfo . builder(null )
10+ builder. ciWorkspace(workspacePath)
11+ def info = builder. build()
12+
13+ info. ciWorkspace == sanitizedPath
14+
15+ where :
16+ workspacePath | sanitizedPath
17+ null | null
18+ " /" | " /"
19+ " /repo/path" | " /repo/path"
20+ " /repo/path/" | " /repo/path"
21+ }
22+ }
Original file line number Diff line number Diff line change @@ -56,7 +56,6 @@ public GitInfo getGitInfo(@Nullable String repositoryPath) {
5656 repositoryPath = NULL_PATH_STRING ;
5757 }
5858
59- // normalize path to avoid creating two entries in the cache
6059 return gitInfoCache .computeIfAbsent (repositoryPath , this ::buildGitInfo );
6160 }
6261
You can’t perform that action at this time.
0 commit comments