From 6d8956e80380d7c5ed21815c4ba0d4dadc08587f Mon Sep 17 00:00:00 2001 From: xxqfamous Date: Mon, 5 Jun 2023 14:29:14 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A4=8D=E6=9D=82=E6=96=87=E4=BB=B6=E5=90=8D?= =?UTF-8?q?=E7=A7=B0=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/repositories_controller.rb | 6 +++--- app/services/gitea/client_service.rb | 3 +++ 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/app/controllers/repositories_controller.rb b/app/controllers/repositories_controller.rb index 6b2d2437a..f981c37b5 100644 --- a/app/controllers/repositories_controller.rb +++ b/app/controllers/repositories_controller.rb @@ -74,7 +74,7 @@ class RepositoriesController < ApplicationController end def sub_entries - file_path_uri = URI.parse(URI.encode(params[:filepath].to_s.strip)) + file_path_uri = URI.escape(URI.encode(params[:filepath].to_s.strip)) if @project.educoder? if params[:type] === 'file' @@ -127,7 +127,7 @@ class RepositoriesController < ApplicationController @commits = Educoder::Repository::Commits::ListService.call(@project&.project_educoder&.repo_name) else if params[:filepath].present? - file_path_uri = URI.parse(URI.encode(params[:filepath].to_s.strip)) + file_path_uri = URI.escape(URI.encode(params[:filepath].to_s.strip)) @hash_commit = Gitea::Repository::Commits::FileListService.new(@owner.login, @project.identifier, file_path_uri, sha: params[:sha], page: params[:page], limit: params[:limit], token: @owner&.gitea_token).call else @@ -323,7 +323,7 @@ class RepositoriesController < ApplicationController # TODO 获取最新commit信息 def project_commits if params[:filepath].present? - file_path_uri = URI.parse(URI.encode(params[:filepath].to_s.strip)) + file_path_uri = URI.escape(URI.encode(params[:filepath].to_s.strip)) Gitea::Repository::Commits::FileListService.new(@project.owner.login, @project.identifier, file_path_uri, sha: get_ref, page: 1, limit: 1, token: @project&.owner&.gitea_token).call else diff --git a/app/services/gitea/client_service.rb b/app/services/gitea/client_service.rb index 62e040d82..5418be159 100644 --- a/app/services/gitea/client_service.rb +++ b/app/services/gitea/client_service.rb @@ -115,6 +115,9 @@ class Gitea::ClientService < ApplicationService url = [api_url(is_hat), api_rest].join('').freeze url = action === 'get' ? url : URI.escape(url) url = URI.escape(url) unless url.ascii_only? + url = url.gsub(")", "%29") if url.to_s.include?(")") + url = url.gsub("]", "%5D") if url.to_s.include?("]") + url = url.gsub("[", "%5B") if url.to_s.include?("[") puts "[gitea] request url: #{url}" return url end