Skip to content

Commit 787e2e3

Browse files
bug #872 Use relative URLs when index.json provides them (nicolas-grekas)
This PR was merged into the 1.x branch. Discussion ---------- Use relative URLs when index.json provides them Fix #868 with help from symfony-tools/recipes-checker@86f5d7f Best reviewed [ignoring whitespaces](https://github.com/symfony/flex/pull/872/files?w=1). Commits ------- c3815a7 Use relative URLs when index.json provides them
2 parents b1fb5d5 + c3815a7 commit 787e2e3

File tree

1 file changed

+23
-12
lines changed

1 file changed

+23
-12
lines changed

src/Downloader.php

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -203,27 +203,38 @@ public function getRecipes(array $operations): array
203203
$version = $version[0].'.'.($version[1] ?? '9999999');
204204

205205
foreach (array_reverse($recipeVersions) as $v => $endpoint) {
206-
if (version_compare($version, $v, '>=')) {
207-
$data['locks'][$package->getName()]['version'] = $version;
208-
$data['locks'][$package->getName()]['recipe']['version'] = $v;
206+
if (version_compare($version, $v, '<')) {
207+
continue;
208+
}
209209

210-
if (null !== $recipeRef && isset($this->endpoints[$endpoint]['_links']['archived_recipes_template'])) {
211-
$urls[] = strtr($this->endpoints[$endpoint]['_links']['archived_recipes_template'], [
212-
'{package_dotted}' => str_replace('/', '.', $package->getName()),
213-
'{ref}' => $recipeRef,
214-
]);
210+
$data['locks'][$package->getName()]['version'] = $version;
211+
$data['locks'][$package->getName()]['recipe']['version'] = $v;
212+
$links = $this->endpoints[$endpoint]['_links'];
215213

216-
break;
214+
if (null !== $recipeRef && isset($links['archived_recipes_template'])) {
215+
if (isset($links['archived_recipes_template_relative'])) {
216+
$links['archived_recipes_template'] = preg_replace('{[^/\?]*+(?=\?|$)}', $links['archived_recipes_template_relative'], $endpoint, 1);
217217
}
218218

219-
$urls[] = strtr($this->endpoints[$endpoint]['_links']['recipe_template'], [
219+
$urls[] = strtr($links['archived_recipes_template'], [
220220
'{package_dotted}' => str_replace('/', '.', $package->getName()),
221-
'{package}' => $package->getName(),
222-
'{version}' => $v,
221+
'{ref}' => $recipeRef,
223222
]);
224223

225224
break;
226225
}
226+
227+
if (isset($links['recipes_template_relative'])) {
228+
$links['recipes_template'] = preg_replace('{[^/\?]*+(?=\?|$)}', $links['recipes_template_relative'], $endpoint, 1);
229+
}
230+
231+
$urls[] = strtr($links['recipe_template'], [
232+
'{package_dotted}' => str_replace('/', '.', $package->getName()),
233+
'{package}' => $package->getName(),
234+
'{version}' => $v,
235+
]);
236+
237+
break;
227238
}
228239

229240
continue;

0 commit comments

Comments
 (0)