Log In
Log In
Places
All Projects
Status Monitor
Collapse sidebar
obs:server:fedora:2.10:testing
obs-server
obs-server-2.10-0031-api-Get-rid-of-obsolete-UR...
Overview
Repositories
Revisions
Requests
Users
Attributes
Meta
File obs-server-2.10-0031-api-Get-rid-of-obsolete-URI-methods-for-Ruby-3.0.patch of Package obs-server
From 52dfdc6db457fb0fc11aee32d112ae6966aa749a Mon Sep 17 00:00:00 2001 From: Oleg Girko <ol@infoserver.lv> Date: Thu, 3 Jun 2021 16:40:55 +0100 Subject: [PATCH] [api] Get rid of obsolete URI methods for Ruby 3.0. URI.escape, URI.encode and URI.unescape was deprecated for a long time, and it's finally removed with the release of Ruby 3.0. This change replaces URI.escape and URI.encode with EscapeUtils.escape_uri, and URI.unescape with EscapeUtils.unescape_uri that do essentially the same. Signed-off-by: Oleg Girko <ol@infoserver.lv> --- src/api/app/controllers/group_controller.rb | 2 +- src/api/app/controllers/person_controller.rb | 4 ++-- src/api/app/helpers/maintenance_helper.rb | 10 +++++----- src/api/app/helpers/webui/webui_helper.rb | 2 +- src/api/app/models/package.rb | 6 +++--- src/api/app/models/package_file.rb | 2 +- src/api/app/models/project.rb | 6 +++--- src/api/app/models/project_config_file.rb | 2 +- src/api/app/models/project_file.rb | 2 +- src/api/app/models/project_meta_file.rb | 2 +- .../spec/controllers/webui/package_controller_spec.rb | 2 +- src/api/spec/factories/packages.rb | 8 ++++---- src/api/spec/models/backend/file_spec.rb | 2 +- src/api/spec/models/package_spec.rb | 2 +- src/api/test/functional/request_controller_test.rb | 2 +- 15 files changed, 27 insertions(+), 27 deletions(-) diff --git a/src/api/app/controllers/group_controller.rb b/src/api/app/controllers/group_controller.rb index 7ade6d8342..0ff38eefe7 100644 --- a/src/api/app/controllers/group_controller.rb +++ b/src/api/app/controllers/group_controller.rb @@ -65,7 +65,7 @@ class GroupController < ApplicationController # POST for editing it, adding or remove users def command - group = Group.find_by_title!(URI.unescape(params[:title])) + group = Group.find_by_title!(EscapeUtils.unescape_uri(params[:title])) authorize group, :update? user = User.find_by_login!(params[:userid]) if params[:userid] diff --git a/src/api/app/controllers/person_controller.rb b/src/api/app/controllers/person_controller.rb index f5188d70d4..4c6ff09a67 100644 --- a/src/api/app/controllers/person_controller.rb +++ b/src/api/app/controllers/person_controller.rb @@ -230,9 +230,9 @@ class PersonController < ApplicationController login = xml.elements['/userchangepasswd/login'].text password = xml.elements['/userchangepasswd/password'].text - login = URI.unescape(login) + login = EscapeUtils.unescape_uri(login) - change_password(login, URI.unescape(password)) + change_password(login, EscapeUtils.unescape_uri(password)) render_ok end diff --git a/src/api/app/helpers/maintenance_helper.rb b/src/api/app/helpers/maintenance_helper.rb index ac554fcf19..1af5e0be78 100644 --- a/src/api/app/helpers/maintenance_helper.rb +++ b/src/api/app/helpers/maintenance_helper.rb @@ -93,7 +93,7 @@ module MaintenanceHelper link['package'] = link['package'].gsub(/\..*/, '') + target_package_name.gsub(/.*\./, '.') # adapt link target with suffix link_xml = link.to_xml # rubocop:disable Metrics/LineLength - Backend::Connection.put "/source/#{URI.escape(target_project.name)}/#{URI.escape(target_package_name)}/_link?rev=repository&user=#{CGI.escape(User.session!.login)}", link_xml + Backend::Connection.put "/source/#{EscapeUtils.escape_uri(target_project.name)}/#{EscapeUtils.escape_uri(target_package_name)}/_link?rev=repository&user=#{CGI.escape(User.session!.login)}", link_xml # rubocop:enable Metrics/LineLength md5 = Digest::MD5.hexdigest(link_xml) # commit with noservice parameter @@ -104,7 +104,7 @@ module MaintenanceHelper comment: "Set local link to #{target_package_name} via maintenance_release request" } upload_params[:requestid] = action.bs_request.number if action - upload_path = "/source/#{URI.escape(target_project.name)}/#{URI.escape(target_package_name)}" + upload_path = "/source/#{EscapeUtils.escape_uri(target_project.name)}/#{EscapeUtils.escape_uri(target_package_name)}" upload_path << Backend::Connection.build_query_from_hash(upload_params, [:user, :comment, :cmd, :noservice, :requestid]) answer = Backend::Connection.post upload_path, "<directory> <entry name=\"_link\" md5=\"#{md5}\" /> </directory>" tpkg.sources_changed(dir_xml: answer) @@ -127,7 +127,7 @@ module MaintenanceHelper rev: 'repository', comment: "Set link to #{target_package_name} via maintenance_release request" } - upload_path = "/source/#{URI.escape(target_project.name)}/#{URI.escape(base_package_name)}/_link" + upload_path = "/source/#{EscapeUtils.escape_uri(target_project.name)}/#{EscapeUtils.escape_uri(base_package_name)}/_link" upload_path << Backend::Connection.build_query_from_hash(upload_params, [:user, :rev]) link = "<link package='#{target_package_name}' cicount='copy' />\n" md5 = Digest::MD5.hexdigest(link) @@ -136,7 +136,7 @@ module MaintenanceHelper upload_params[:cmd] = 'commitfilelist' upload_params[:noservice] = '1' upload_params[:requestid] = request.number if request - upload_path = "/source/#{URI.escape(target_project.name)}/#{URI.escape(base_package_name)}" + upload_path = "/source/#{EscapeUtils.escape_uri(target_project.name)}/#{EscapeUtils.escape_uri(base_package_name)}" upload_path << Backend::Connection.build_query_from_hash(upload_params, [:user, :comment, :cmd, :noservice, :requestid]) answer = Backend::Connection.post upload_path, "<directory> <entry name=\"_link\" md5=\"#{md5}\" /> </directory>" lpkg.sources_changed(dir_xml: answer) @@ -227,7 +227,7 @@ module MaintenanceHelper cp_params[:setrelease] = setrelease if setrelease cp_params[:multibuild] = '1' unless source_package_name.include?(':') # rubocop:disable Metrics/LineLength - cp_path = "/build/#{CGI.escape(target_repository.project.name)}/#{URI.escape(target_repository.name)}/#{URI.escape(arch.name)}/#{URI.escape(target_package_name)}" + cp_path = "/build/#{CGI.escape(target_repository.project.name)}/#{EscapeUtils.escape_uri(target_repository.name)}/#{EscapeUtils.escape_uri(arch.name)}/#{EscapeUtils.escape_uri(target_package_name)}" # rubocop:enable Metrics/LineLength cp_path << Backend::Connection.build_query_from_hash(cp_params, [:cmd, :oproject, :opackage, :orepository, :setupdateinfoid, diff --git a/src/api/app/helpers/webui/webui_helper.rb b/src/api/app/helpers/webui/webui_helper.rb index 455dfce457..45bf83fa7f 100644 --- a/src/api/app/helpers/webui/webui_helper.rb +++ b/src/api/app/helpers/webui/webui_helper.rb @@ -11,7 +11,7 @@ module Webui::WebuiHelper cc = ('&cc=' + email_list[1..-1].join('&cc=')) if email_list end - URI.escape( + EscapeUtils.escape_uri( "#{@configuration['bugzilla_url']}/enter_bug.cgi?classification=7340&product=openSUSE.org" \ "&component=3rd party software&assigned_to=#{assignee}#{cc}&short_desc=#{desc}" ) diff --git a/src/api/app/models/package.rb b/src/api/app/models/package.rb index ff9a0e29fe..f9aa06b0e2 100644 --- a/src/api/app/models/package.rb +++ b/src/api/app/models/package.rb @@ -489,8 +489,8 @@ class Package < ApplicationRecord end def self.source_path(project, package, file = nil, opts = {}) - path = "/source/#{URI.escape(project)}/#{URI.escape(package)}" - path += "/#{URI.escape(file)}" if file.present? + path = "/source/#{EscapeUtils.escape_uri(project)}/#{EscapeUtils.escape_uri(package)}" + path += "/#{EscapeUtils.escape_uri(file)}" if file.present? path += '?' + opts.to_query if opts.present? path end @@ -1420,7 +1420,7 @@ class Package < ApplicationRecord permitted_params = params.permit(:repository, :arch, :package, :code, :wipe) # do not use project.name because we missuse the package source container for build container operations - Backend::Connection.post("/build/#{URI.escape(build_project)}?cmd=#{command}&#{permitted_params.to_h.to_query}") + Backend::Connection.post("/build/#{EscapeUtils.escape_uri(build_project)}?cmd=#{command}&#{permitted_params.to_h.to_query}") rescue Backend::Error, Timeout::Error, Project::WritePermissionError => e errors.add(:base, e.message) return false diff --git a/src/api/app/models/package_file.rb b/src/api/app/models/package_file.rb index 6b27fa13b6..1d86f16574 100644 --- a/src/api/app/models/package_file.rb +++ b/src/api/app/models/package_file.rb @@ -8,6 +8,6 @@ class PackageFile < Backend::File # calculates the real url on the backend to search the file def full_path(query = {}) - URI.encode("/source/#{project_name}/#{package_name}/#{name}") + "?#{query.to_query}" + EscapeUtils.escape_uri("/source/#{project_name}/#{package_name}/#{name}") + "?#{query.to_query}" end end diff --git a/src/api/app/models/project.rb b/src/api/app/models/project.rb index 457bc9dcca..b43a96667c 100644 --- a/src/api/app/models/project.rb +++ b/src/api/app/models/project.rb @@ -1087,7 +1087,7 @@ class Project < ApplicationRecord # copy entire project in the backend begin - path = "/source/#{URI.escape(name)}" + path = "/source/#{EscapeUtils.escape_uri(name)}" path << Backend::Connection.build_query_from_hash(params, [:cmd, :user, :comment, :oproject, :withbinaries, :withhistory, :makeolder, :makeoriginolder, :noservice]) @@ -1363,8 +1363,8 @@ class Project < ApplicationRecord end def self.source_path(project, file = nil, opts = {}) - path = "/source/#{URI.escape(project)}" - path += "/#{URI.escape(file)}" if file.present? + path = "/source/#{EscapeUtils.escape_uri(project)}" + path += "/#{EscapeUtils.escape_uri(file)}" if file.present? path += '?' + opts.to_query if opts.present? path end diff --git a/src/api/app/models/project_config_file.rb b/src/api/app/models/project_config_file.rb index cb52153a5c..5719d3f3d9 100644 --- a/src/api/app/models/project_config_file.rb +++ b/src/api/app/models/project_config_file.rb @@ -6,7 +6,7 @@ class ProjectConfigFile < ProjectFile # calculates the real url on the backend to search the file def full_path(query = {}) - URI.encode("/source/#{project_name}/#{name}") + "?#{query.to_query}" + EscapeUtils.escape_uri("/source/#{project_name}/#{name}") + "?#{query.to_query}" end # You dont want to change name of _config diff --git a/src/api/app/models/project_file.rb b/src/api/app/models/project_file.rb index 8243708fb7..030172844d 100644 --- a/src/api/app/models/project_file.rb +++ b/src/api/app/models/project_file.rb @@ -11,6 +11,6 @@ class ProjectFile < Backend::File # calculates the real url on the backend to search the file def full_path(query = {}) - URI.encode("/source/#{project_name}/_project/#{name}") + "?#{query.to_query}" + EscapeUtils.escape_uri("/source/#{project_name}/_project/#{name}") + "?#{query.to_query}" end end diff --git a/src/api/app/models/project_meta_file.rb b/src/api/app/models/project_meta_file.rb index 221fb811f3..3d71a72e19 100644 --- a/src/api/app/models/project_meta_file.rb +++ b/src/api/app/models/project_meta_file.rb @@ -6,7 +6,7 @@ class ProjectMetaFile < ProjectFile # calculates the real url on the backend to search the file def full_path(query = {}) - URI.encode("/source/#{project_name}/#{name}") + "?#{query.to_query}" + EscapeUtils.escape_uri("/source/#{project_name}/#{name}") + "?#{query.to_query}" end # You dont want to change name of _meta diff --git a/src/api/spec/controllers/webui/package_controller_spec.rb b/src/api/spec/controllers/webui/package_controller_spec.rb index 41cd5074ec..3f9955f11f 100644 --- a/src/api/spec/controllers/webui/package_controller_spec.rb +++ b/src/api/spec/controllers/webui/package_controller_spec.rb @@ -497,7 +497,7 @@ RSpec.describe Webui::PackageController, vcr: true do it { expect(flash[:success]).to eq("The file '学习总结' has been successfully saved.") } it 'creates the file' do expect { source_package.source_file('学习总结') }.not_to raise_error - expect(URI.encode(source_package.source_file('学习总结'))).to eq(URI.encode(file_to_upload)) + expect(EscapeUtils.escape_uri(source_package.source_file('学习总结'))).to eq(EscapeUtils.escape_uri(file_to_upload)) end end diff --git a/src/api/spec/factories/packages.rb b/src/api/spec/factories/packages.rb index 3d784b9561..43329713b5 100644 --- a/src/api/spec/factories/packages.rb +++ b/src/api/spec/factories/packages.rb @@ -80,7 +80,7 @@ FactoryBot.define do # NOTE: Enable global write through when writing new VCR cassetes. # ensure the backend knows the project if CONFIG['global_write_through'] - Backend::Connection.put("/source/#{URI.escape(package.project.name)}/#{URI.escape(package.name)}/_service", '<services/>') + Backend::Connection.put("/source/#{EscapeUtils.escape_uri(package.project.name)}/#{EscapeUtils.escape_uri(package.name)}/_service", '<services/>') end end end @@ -90,7 +90,7 @@ FactoryBot.define do # NOTE: Enable global write through when writing new VCR cassetes. # ensure the backend knows the project if CONFIG['global_write_through'] - Backend::Connection.put("/source/#{URI.escape(package.project.name)}/#{URI.escape(package.name)}/_service", '<service>broken</service>') + Backend::Connection.put("/source/#{EscapeUtils.escape_uri(package.project.name)}/#{EscapeUtils.escape_uri(package.name)}/_service", '<service>broken</service>') end end end @@ -106,7 +106,7 @@ FactoryBot.define do # ensure the backend knows the project if CONFIG['global_write_through'] full_path = "/source/#{package.project.name}/#{package.name}/#{evaluator.changes_file_name}" - Backend::Connection.put(URI.escape(full_path), evaluator.changes_file_content) + Backend::Connection.put(EscapeUtils.escape_uri(full_path), evaluator.changes_file_content) end end end @@ -135,7 +135,7 @@ FactoryBot.define do # ensure the backend knows the project if CONFIG['global_write_through'] full_path = "/source/#{package.project.name}/#{package.name}/#{evaluator.kiwi_file_name}" - Backend::Connection.put(URI.escape(full_path), evaluator.kiwi_file_content) + Backend::Connection.put(EscapeUtils.escape_uri(full_path), evaluator.kiwi_file_content) end end end diff --git a/src/api/spec/models/backend/file_spec.rb b/src/api/spec/models/backend/file_spec.rb index 94bc6a996a..002cedec7b 100644 --- a/src/api/spec/models/backend/file_spec.rb +++ b/src/api/spec/models/backend/file_spec.rb @@ -18,7 +18,7 @@ RSpec.describe Backend::File, vcr: true do class TestBackendFile < Backend::File attr_accessor :somefile def full_path(_query) - URI.encode(somefile) + EscapeUtils.escape_uri(somefile) end end diff --git a/src/api/spec/models/package_spec.rb b/src/api/spec/models/package_spec.rb index bfaea76fa9..84bdeab36b 100644 --- a/src/api/spec/models/package_spec.rb +++ b/src/api/spec/models/package_spec.rb @@ -644,7 +644,7 @@ RSpec.describe Package, vcr: true do before do if CONFIG['global_write_through'] full_path = "/source/#{package.project.name}/#{package.name}/lorem.changes" - Backend::Connection.put(URI.escape(full_path), 'Lorem ipsum dolorem') + Backend::Connection.put(EscapeUtils.escape_uri(full_path), 'Lorem ipsum dolorem') end end diff --git a/src/api/test/functional/request_controller_test.rb b/src/api/test/functional/request_controller_test.rb index ad82c24034..67babcaa8d 100644 --- a/src/api/test/functional/request_controller_test.rb +++ b/src/api/test/functional/request_controller_test.rb @@ -1292,7 +1292,7 @@ class RequestControllerTest < ActionDispatch::IntegrationTest assert_xml_tag(tag: 'request', attributes: { id: id }) # via POST - post '/search/request', params: URI.encode("match=(state/@name='new' or state/@name='review') and (action/target/@project='kde4' and action/target/@package='wpa_supplicant')") + post '/search/request', params: EscapeUtils.escape_uri("match=(state/@name='new' or state/@name='review') and (action/target/@project='kde4' and action/target/@package='wpa_supplicant')") assert_response :success assert_xml_tag(tag: 'request', attributes: { id: id }) -- 2.35.3
Locations
Projects
Search
Status Monitor
Help
OpenBuildService.org
Documentation
API Documentation
Contact
Support
@OBShq
The Open Build Service is an
openSUSE project
.
Log In
Places
Places
All Projects
Status Monitor