From 369c19ab1a5ece459e92a7417460c8ad36b05e90 Mon Sep 17 00:00:00 2001 From: Yahnis Elsts Date: Thu, 28 Jan 2021 19:10:17 +0200 Subject: [PATCH] BitBucket: Use commit hash instead of branch name when the branch is not URL-safe. Apparently, the "/src" subsection of the BitBucket API doesn't do well with branch names that contain slashes. urlencode() doesn't help. See #409 for the initial report. --- Puc/v4p10/Vcs/BitBucketApi.php | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/Puc/v4p10/Vcs/BitBucketApi.php b/Puc/v4p10/Vcs/BitBucketApi.php index 8ec506c..eba3a91 100644 --- a/Puc/v4p10/Vcs/BitBucketApi.php +++ b/Puc/v4p10/Vcs/BitBucketApi.php @@ -59,8 +59,16 @@ if ( !class_exists('Puc_v4p10_Vcs_BitBucketApi', false) ): return null; } + //The "/src/{stuff}/{path}" endpoint doesn't seem to handle branch names that contain slashes. + //If we don't encode the slash, we get a 404. If we encode it as "%2F", we get a 401. + //To avoid issues, if the branch name is not URL-safe, let's use the commit hash instead. + $ref = $branch->name; + if ((urlencode($ref) !== $ref) && isset($branch->target->hash)) { + $ref = $branch->target->hash; + } + return new Puc_v4p10_Vcs_Reference(array( - 'name' => $branch->name, + 'name' => $ref, 'updated' => $branch->target->date, 'downloadUrl' => $this->getDownloadUrl($branch->name), ));