@@ -290,18 +290,20 @@ func (pkgs *PhpPackagesCollection) OverrideVersionsFile() string {
290
290
//
291
291
// Returns:
292
292
// - []PhpPackage with extracted package info, sorted by package name
293
+ // - []string notes to be added to the test
293
294
// - nil upon error processing JSON
294
295
//
295
296
// Notes: Currently only supports an application created with composer
296
- func (pkgs * PhpPackagesCollection ) GatherInstalledPackages () ([]PhpPackage , error ) {
297
+ func (pkgs * PhpPackagesCollection ) GatherInstalledPackages () ([]PhpPackage , [] string , error ) {
297
298
298
299
var err error
299
300
300
301
if nil == pkgs {
301
- return nil , fmt .Errorf ("GatherInstallPackages(): pkgs is nil" )
302
+ return nil , nil , fmt .Errorf ("GatherInstallPackages(): pkgs is nil" )
302
303
}
303
304
304
305
var supported []string
306
+ var notes []string
305
307
306
308
// get list of packages we expected the agent to detect
307
309
// this can be one of 3 scenarios:
@@ -331,12 +333,12 @@ func (pkgs *PhpPackagesCollection) GatherInstalledPackages() ([]PhpPackage, erro
331
333
if 0 < len (pkgs .config .supportedListFile ) {
332
334
supported , err = LoadSupportedPackagesList (pkgs .config .path , pkgs .config .supportedListFile )
333
335
if nil != err {
334
- return nil , err
336
+ return nil , nil , err
335
337
}
336
338
} else if 0 < len (pkgs .config .expectedPackages ) {
337
339
supported = pkgs .config .expectedPackages
338
340
} else if ! pkgs .config .expectAllDetected {
339
- return nil , fmt .Errorf ("Error determining expected packages - supported_packages and expected_packages are both empty " +
341
+ return nil , nil , fmt .Errorf ("Error determining expected packages - supported_packages and expected_packages are both empty " +
340
342
"and expect_all is false" )
341
343
}
342
344
@@ -366,6 +368,16 @@ func (pkgs *PhpPackagesCollection) GatherInstalledPackages() ([]PhpPackage, erro
366
368
} else {
367
369
version = v .Version
368
370
}
371
+
372
+ // Remove any additional information extracted (hashes, etc).
373
+ // The composer versioning standard is to not include any spaces
374
+ // yet sometimes this standard is broken
375
+ version_splits := strings .Split (version , " " )
376
+ if len (version_splits ) > 1 {
377
+ notes = append (notes , fmt .Sprintf ("Used shortened package version from composer. Originally was \" %s\" " , version ))
378
+ version = version_splits [0 ]
379
+ }
380
+
369
381
pkgs .packages = append (pkgs .packages , PhpPackage {v .Name , version })
370
382
//fmt.Printf(" -> %s in supported!\n", v.Name)
371
383
} else {
@@ -402,15 +414,15 @@ func (pkgs *PhpPackagesCollection) GatherInstalledPackages() ([]PhpPackage, erro
402
414
}
403
415
}
404
416
} else {
405
- return nil , fmt .Errorf ("ERROR - unknown method '%s'\n " , splitCmd [0 ])
417
+ return nil , nil , fmt .Errorf ("ERROR - unknown method '%s'\n " , splitCmd [0 ])
406
418
}
407
419
408
420
// sort by package name to aid comparision later
409
421
sort .Slice (pkgs .packages , func (i , j int ) bool {
410
422
return pkgs .packages [i ].Name < pkgs .packages [j ].Name
411
423
})
412
424
413
- return pkgs .packages , nil
425
+ return pkgs .packages , notes , nil
414
426
}
415
427
416
428
// convert PhpPackage to collector JSON representation
0 commit comments