@@ -238,20 +238,28 @@ func (s *Scanner) Scan(ctx context.Context, layer *claircore.Layer) ([]*claircor
238
238
// claircore.Package mapping code around embedded jars. There's a
239
239
// testcase to be written, there.
240
240
241
- // Only examine the last element of the source list:
242
- js := strings .Split (i .Source , ":" )
243
- switch l := js [len (js )- 1 ]; {
241
+ idx := strings .LastIndex (i .Source , ":" )
242
+ // If the top-level JAR file can only be identified by its name,
243
+ // i.Source will just be `.`
244
+ // In this case, PackageDB should just be the filepath, n.
245
+ // Otherwise, use i.Source.
246
+ pkgDB := n
247
+ if idx != - 1 {
248
+ pkgDB = i .Source [:idx ]
249
+ }
250
+ // Only examine anything after the last colon (or the entire path if there is no colon).
251
+ switch l := i .Source [idx + 1 :]; {
244
252
case strings .HasSuffix (l , "pom.properties" ):
245
253
fallthrough
246
254
case s .root != nil && i .Source == s .root .String ():
247
255
// Populate as a maven artifact.
248
- pkg .PackageDB = `maven:` + n
256
+ pkg .PackageDB = `maven:` + pkgDB
249
257
case l == "META-INF/MANIFEST.MF" :
250
258
// information pulled from a manifest file
251
- pkg .PackageDB = `jar:` + n
259
+ pkg .PackageDB = `jar:` + pkgDB
252
260
case l == "." :
253
261
// Name guess.
254
- pkg .PackageDB = `file:` + n
262
+ pkg .PackageDB = `file:` + pkgDB
255
263
default :
256
264
return nil , fmt .Errorf ("java: martian Info: %+v" , i )
257
265
}
0 commit comments