From 939955fb2cf15610e2b4f1dd0109f883d73fb930 Mon Sep 17 00:00:00 2001 From: Jon Dufresne Date: Tue, 15 Mar 2016 14:14:09 -0700 Subject: [PATCH] Prefer the first https:// PEAR mirror; avoid http://. Fixes #5069 --- src/Composer/Repository/Pear/ChannelReader.php | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/Composer/Repository/Pear/ChannelReader.php b/src/Composer/Repository/Pear/ChannelReader.php index 849055959..e8e992ca5 100644 --- a/src/Composer/Repository/Pear/ChannelReader.php +++ b/src/Composer/Repository/Pear/ChannelReader.php @@ -80,8 +80,18 @@ class ChannelReader extends BaseChannelReader $channelXml->registerXPathNamespace('ns', self::CHANNEL_NS); foreach ($supportedVersions as $version) { - $xpathTest = "ns:servers/ns:primary/ns:rest/ns:baseurl[@type='{$version}']"; + $xpathTest = "ns:servers/ns:*/ns:rest/ns:baseurl[@type='{$version}']"; $testResult = $channelXml->xpath($xpathTest); + + foreach ($testResult as $result) { + // Choose first https:// option. + $result = (string) $result; + if (preg_match('{^https://}i', $result)) { + return array('version' => $version, 'baseUrl' => $result); + } + } + + // Fallback to non-https if it does not exist. if (count($testResult) > 0) { return array('version' => $version, 'baseUrl' => (string) $testResult[0]); }