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), ));