From 4a718ac2bcfc54f64369d65a2a974922b411da6c Mon Sep 17 00:00:00 2001 From: caoyanyi Date: Thu, 24 Feb 2022 10:17:55 +0800 Subject: [PATCH 1/2] * Modify branch encode. --- module/gitlab/control.php | 20 ++++++++++++-------- module/gitlab/model.php | 3 +++ module/gitlab/view/browsebranchpriv.html.php | 2 +- module/gitlab/view/browsetag.html.php | 2 +- module/gitlab/view/browsetagpriv.html.php | 2 +- module/gitlab/view/createbranchpriv.html.php | 2 +- 6 files changed, 19 insertions(+), 12 deletions(-) diff --git a/module/gitlab/control.php b/module/gitlab/control.php index 509b95ca54..f7bfe3ae4e 100644 --- a/module/gitlab/control.php +++ b/module/gitlab/control.php @@ -924,7 +924,7 @@ class gitlab extends control } /* Fix error when request type is PATH_INFO and the branch name contains '-'.*/ - if($branch) $branch = str_replace('*', '-', $branch); + if($branch) $branch = urldecode(helper::safe64Decode($branch)); if($_POST) { @@ -935,7 +935,7 @@ class gitlab extends control } $branchPriv = new stdClass(); - $branchPriv->name = ''; + $branchPriv->name = ''; $branchPriv->mergeAccessLevel = 40; // Initialize data, and the operation authority is the maintainers by default. $branchPriv->pushAccessLevel = 40; // Initialize data, and the operation authority is the maintainers by default. @@ -945,6 +945,7 @@ class gitlab extends control { $title = $this->lang->gitlab->editBranchPriv; $branchPriv = $this->gitlab->apiGetSingleBranchPriv($gitlabID, $projectID, $branch); + $branchPriv->name = helper::safe64Encode(urlencode($branchPriv->name)); $branchPriv->mergeAccessLevel = $this->gitlab->checkAccessLevel($branchPriv->merge_access_levels); $branchPriv->pushAccessLevel = $this->gitlab->checkAccessLevel($branchPriv->push_access_levels); } @@ -956,7 +957,11 @@ class gitlab extends control $branches = array(); foreach($gitlabBranches as $oneBranch) { - if(!in_array($oneBranch->name, $protectNames) || $oneBranch->name == $branch) $branches[$oneBranch->name] = $oneBranch->name; + if(!in_array($oneBranch->name, $protectNames) || $oneBranch->name == $branch) + { + $branchName = helper::safe64Encode(urlencode($oneBranch->name)); + $branches[$branchName] = $oneBranch->name; + } } $this->view->title = $this->lang->gitlab->common . $this->lang->colon . $title; @@ -1006,12 +1011,11 @@ class gitlab extends control if($confirm != 'yes') { - $branch = urlencode($branch); die(js::confirm($this->lang->gitlab->branch->confirmDelete , inlink('deleteBranchPriv', "gitlabID=$gitlabID&projectID=$projectID&branch=$branch&confirm=yes"))); } /* Fix error when request type is PATH_INFO and the branch name contains '-'.*/ - $branch = str_replace('*', '-', $branch); + $branch = urldecode(helper::safe64Decode($branch)); $reponse = $this->gitlab->apiDeleteBranchPriv($gitlabID, $projectID, $branch); /* If the status code beginning with 20 is returned or empty is returned, it is successful. */ @@ -1223,7 +1227,7 @@ class gitlab extends control } /* Fix error when request type is PATH_INFO and the tag name contains '-'.*/ - $tag = str_replace('*', '-', $tag); + $tag = urldecode(helper::safe64Decode($tag)); if($_POST) { @@ -1265,7 +1269,7 @@ class gitlab extends control } /* Fix error when request type is PATH_INFO and the tag name contains '-'.*/ - $tag = str_replace('*', '-', $tag); + $tag = urldecode(helper::safe64Decode($tag)); $reponse = $this->gitlab->apiDeleteTagPriv($gitlabID, $projectID, $tag); /* If the status code beginning with 20 is returned or empty is returned, it is successful. */ @@ -1677,7 +1681,7 @@ class gitlab extends control if($confirm != 'yes') die(js::confirm($this->lang->gitlab->tag->confirmDelete , inlink('deleteTag', "gitlabID=$gitlabID&projectID=$projectID&tagName=$tagName&confirm=yes"))); /* Fix error when request type is PATH_INFO and the tag name contains '-'.*/ - $tagName = str_replace('*', '-', $tagName); + $tagName = urldecode(helper::safe64Decode($tagName)); $reponse = $this->gitlab->apiDeleteTag($gitlabID, $projectID, $tagName); /* If the status code beginning with 20 is returned or empty is returned, it is successful. */ diff --git a/module/gitlab/model.php b/module/gitlab/model.php index cc2a7c4a98..0d5cd7ded2 100644 --- a/module/gitlab/model.php +++ b/module/gitlab/model.php @@ -2577,6 +2577,7 @@ class gitlabModel extends model return false; } + $priv->name = urldecode(helper::safe64Decode($priv->name)); $singleBranch = $this->apiGetSingleBranchPriv($gitlabID, $projectID, $priv->name); if(empty($branch) && !empty($singleBranch->id)) { @@ -2611,6 +2612,7 @@ class gitlabModel extends model if(empty($gitlabID)) return false; if(empty($projectID)) return false; if(empty($priv->name)) return false; + $priv->name = html_entity_decode($priv->name, ENT_QUOTES); $url = sprintf($this->getApiRoot($gitlabID), "/projects/" . $projectID . '/protected_branches'); return json_decode(commonModel::http($url, $priv)); } @@ -2627,6 +2629,7 @@ class gitlabModel extends model public function apiDeleteBranchPriv($gitlabID, $projectID, $branch) { if(empty($gitlabID)) return false; + $branch = urlencode($branch); $apiRoot = $this->getApiRoot($gitlabID); $url = sprintf($apiRoot, "/projects/{$projectID}/protected_branches/{$branch}"); return json_decode(commonModel::http($url, array(), $options = array(CURLOPT_CUSTOMREQUEST => 'DELETE'))); diff --git a/module/gitlab/view/browsebranchpriv.html.php b/module/gitlab/view/browsebranchpriv.html.php index eb873d3e3d..ff40ef0c0f 100644 --- a/module/gitlab/view/browsebranchpriv.html.php +++ b/module/gitlab/view/browsebranchpriv.html.php @@ -63,7 +63,7 @@ name); + $branchName = helper::safe64Encode(urlencode($branch->name)); if(common::hasPriv('gitlab', 'editBranchPriv')) common::printLink('gitlab', 'editBranchPriv', "gitlabID=$gitlabID&projectID=$projectID&branch=$branchName", " ", '', "title={$lang->gitlab->editBranchPriv} class='btn btn-primary'"); if(common::hasPriv('gitlab', 'deleteBranchPriv')) echo html::a($this->createLink('gitlab', 'deleteBranchPriv', "gitlabID=$gitlabID&projectID=$projectID&branch=$branchName"), '', 'hiddenwin', "title='{$lang->gitlab->deleteBranchPriv}' class='btn'"); ?> diff --git a/module/gitlab/view/browsetag.html.php b/module/gitlab/view/browsetag.html.php index 9eb7114403..517aea6750 100644 --- a/module/gitlab/view/browsetag.html.php +++ b/module/gitlab/view/browsetag.html.php @@ -68,7 +68,7 @@ name); + $tagName = helper::safe64Encode(urlencode($gitlabTag->name)); $isDisabled = $gitlabTag->protected ? 'disabled' : ''; common::printLink('gitlab', 'deleteTag', "gitlabID=$gitlabID&projectID={$projectID}&tag_name=$tagName", " ", '', "title='{$lang->gitlab->deleteTag}' class='btn' target='hiddenwin' $isDisabled"); ?> diff --git a/module/gitlab/view/browsetagpriv.html.php b/module/gitlab/view/browsetagpriv.html.php index a76ff40dd5..c3862ddccd 100644 --- a/module/gitlab/view/browsetagpriv.html.php +++ b/module/gitlab/view/browsetagpriv.html.php @@ -64,7 +64,7 @@ name); + $tagName = helper::safe64Encode(urlencode($gitlabTag->name)); common::printLink('gitlab', 'editTagPriv', "gitlabID=$gitlabID&projectID=$projectID&tag_name=$tagName", " ", '', "title={$lang->gitlab->editTagPriv} class='btn btn-primary'"); common::printLink('gitlab', 'deleteTagPriv', "gitlabID=$gitlabID&projectID={$projectID}&tag_name=$tagName", " ", '', "title='{$lang->gitlab->deleteTagPriv}' class='btn btn-primary' target='hiddenwin' onclick='if(confirm(\"{$lang->gitlab->tag->protectConfirmDel}\")==false) return false;'"); ?> diff --git a/module/gitlab/view/createbranchpriv.html.php b/module/gitlab/view/createbranchpriv.html.php index ee4d999bc8..1c28f751fc 100644 --- a/module/gitlab/view/createbranchpriv.html.php +++ b/module/gitlab/view/createbranchpriv.html.php @@ -18,7 +18,7 @@

- + name);?> From 8ad5a1236fca79c2e3108775b94e00bfaecfe37c Mon Sep 17 00:00:00 2001 From: caoyanyi Date: Thu, 24 Feb 2022 10:34:41 +0800 Subject: [PATCH 2/2] * Modify hidden param. --- module/gitlab/view/createbranchpriv.html.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/module/gitlab/view/createbranchpriv.html.php b/module/gitlab/view/createbranchpriv.html.php index 1c28f751fc..db316291ba 100644 --- a/module/gitlab/view/createbranchpriv.html.php +++ b/module/gitlab/view/createbranchpriv.html.php @@ -18,7 +18,7 @@

- name);?> + name) echo html::hidden('name', $branchPriv->name);?>
gitlab->branch->name;?>
gitlab->branch->name;?>