Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support advisories from multiple repositories for the same package #11436

Merged
merged 4 commits into from May 7, 2023

Conversation

mxr576
Copy link
Contributor

@mxr576 mxr576 commented Apr 20, 2023

Closes #11435.

unset($packageConstraintMap[$nameFound]);
}

$advisories = array_merge($advisories, $result['advisories']);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Getting rid of array_merge() in a loop is also a performance improvement.

}

$advisories = array_merge_recursive(...$advisories);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a bad idea to me, as advisories themselves are also arrays so a recursive merge could end up doing weird things. This should be array_merge(...$advisories) instead (also, be careful if $advisories is empty if no repository supports advisories, as both array_merge and array_merge_recursive require at least one argument)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the review.

  1. Used array_merge originally but it did not create the expected result. I would also avoid nested merging for sure.
  2. You are right about the second part, calling array_merge* without an argument is only possible since 7.4.0 and Composer requires 7.2.5.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. but it did not create the expected result.

what do you mean with that ? AFAICT, you need to merge only the first level of the list (to do the equivalent of what $advisories = array_merge($advisories, $result['advisories']) was doing in the loop), and that's exactly what array_merge(...$advisories) will be doing.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Additional info for the 1st:

The task
image

with array_merge()
image

with array_merge_recursive()

image

}

$advisories = array_merge_recursive(...$advisories);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. but it did not create the expected result.

what do you mean with that ? AFAICT, you need to merge only the first level of the list (to do the equivalent of what $advisories = array_merge($advisories, $result['advisories']) was doing in the loop), and that's exactly what array_merge(...$advisories) will be doing.

}

$advisories = array_merge($advisories, $result['advisories']);
$advisories[] = $repository->getSecurityAdvisories($packageConstraintMap, $allowPartialAdvisories)['advisories'];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This variable should probably be renamed to $repositoryAdvisories instead of $advisories as it is not a list of advisories (you get the list of advisories only after the merge). This would make the code easier to read IMO.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✔️

@mxr576 mxr576 requested a review from stof April 21, 2023 10:58
@Seldaek Seldaek added this to the 2.6 milestone May 7, 2023
@Seldaek Seldaek added the Feature label May 7, 2023
@Seldaek Seldaek merged commit 57a48df into composer:main May 7, 2023
18 checks passed
@Seldaek
Copy link
Member

Seldaek commented May 7, 2023

Ok let's give this a shot in 2.6 and see.. if it creates any problems we'll deal with them then.

@mxr576
Copy link
Contributor Author

mxr576 commented May 8, 2023

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Multiple repositories should be able to provide advisories for the same package
3 participants