From 834ad2d64a95eb920caa7f20c886d731ce371d34 Mon Sep 17 00:00:00 2001 From: Thorsten Eckel Date: Fri, 1 May 2015 14:12:37 +0200 Subject: [PATCH] Corrected with rubocop cop 'Style/RegexpLiteral'. --- app/controllers/getting_started_controller.rb | 4 ++-- app/controllers/import_otrs_controller.rb | 4 ++-- app/models/avatar.rb | 2 +- app/models/package.rb | 4 ++-- lib/core_ext/string.rb | 12 ++++++------ 5 files changed, 13 insertions(+), 13 deletions(-) diff --git a/app/controllers/getting_started_controller.rb b/app/controllers/getting_started_controller.rb index f19d7ccb4..f9cffaad5 100644 --- a/app/controllers/getting_started_controller.rb +++ b/app/controllers/getting_started_controller.rb @@ -76,7 +76,7 @@ curl http://localhost/api/v1/getting_started -v -u #{login}:#{password} # validate url messages = {} if !Setting.get('system_online_service') - if !params[:url] || params[:url] !~ /^(http|https):\/\/.+?$/ + if !params[:url] || params[:url] !~ %r{^(http|https)://.+?$} messages[:url] = 'A URL looks like http://zammad.example.com' end end @@ -107,7 +107,7 @@ curl http://localhost/api/v1/getting_started -v -u #{login}:#{password} # split url in http_type and fqdn settings = {} if !Setting.get('system_online_service') - if params[:url] =~ /^(http|https):\/\/(.+?)$/ + if params[:url] =~ %r{/^(http|https)://(.+?)$} Setting.set('http_type', $1) settings[:http_type] = $1 Setting.set('fqdn', $2) diff --git a/app/controllers/import_otrs_controller.rb b/app/controllers/import_otrs_controller.rb index 73dbcdaf9..fdb3d99c5 100644 --- a/app/controllers/import_otrs_controller.rb +++ b/app/controllers/import_otrs_controller.rb @@ -6,7 +6,7 @@ class ImportOtrsController < ApplicationController return if setup_done_response # validate - if !params[:url] || params[:url] !~ /^(http|https):\/\/.+?$/ + if !params[:url] || params[:url] !~ %r{^(http|https)://.+?$} render json: { result: 'invalid', message: 'Invalid!', @@ -44,7 +44,7 @@ class ImportOtrsController < ApplicationController suffixes.each {|suffix| url = params[:url] + suffix + '?Action=ZammadMigrator' # strip multible / in url - url.gsub!(/([^:])(\/+\/)/, '\\1/') + url.gsub!(%r{([^:])(/+/)}, '\\1/') response = UserAgent.request( url ) #Setting.set('import_mode', true) diff --git a/app/models/avatar.rb b/app/models/avatar.rb index 4e8d8cb96..963460a0f 100644 --- a/app/models/avatar.rb +++ b/app/models/avatar.rb @@ -110,7 +110,7 @@ add a avatar # twitter workaround to get bigger avatar images # see also https://dev.twitter.com/overview/general/user-profile-images-and-banners - if data[:url] =~ /\/\/pbs.twimg.com\//i + if data[:url] =~ %r{//pbs.twimg.com/}i data[:url].sub!(/normal\.png$/, 'bigger.png') end diff --git a/app/models/package.rb b/app/models/package.rb index 0b01ee5c1..e1eea6e2c 100644 --- a/app/models/package.rb +++ b/app/models/package.rb @@ -82,7 +82,7 @@ class Package < ApplicationModel def self._package_base_dir?(package_base_dir) package = false Dir.glob( package_base_dir + '/*.szpm') do |entry| - package = entry.sub( /^.*\/(.+?)\.szpm$/, '\1') + package = entry.sub( %r{^.*/(.+?)\.szpm$}, '\1') end if package == false raise "Can't link package, '#{package_base_dir}' is no package source directory!" @@ -133,7 +133,7 @@ class Package < ApplicationModel entry = entry.sub( '//', '/' ) file = entry file = file.sub( /#{package_base_dir.to_s}/, '' ) - file = file.sub( /^\//, '' ) + file = file.sub( %r{^/}, '' ) # ignore files if file =~ /^README/ diff --git a/lib/core_ext/string.rb b/lib/core_ext/string.rb index 7dae03766..c4e73b2f4 100644 --- a/lib/core_ext/string.rb +++ b/lib/core_ext/string.rb @@ -83,10 +83,10 @@ class String string.gsub!( /^\s*/m, '' ) # pre/code handling 1/2 - string.gsub!( /
(.+?)<\/pre>/m ) { |placeholder|
+    string.gsub!( %r{
(.+?)
}m ) { |placeholder| placeholder = placeholder.gsub(/\n/, '###BR###') } - string.gsub!( /(.+?)<\/code>/m ) { |placeholder| + string.gsub!( %r{(.+?)/}m ) { |placeholder| placeholder = placeholder.gsub(/\n/, '###BR###') } @@ -103,12 +103,12 @@ class String string.gsub!(/]*)>/i, '> ') # add hr - string.gsub!(/]*)>/i, "___\n") + string.gsub!(%r{]*)>}i, "___\n") # add new lines - string.gsub!( /\<(br|table)(|\/| [^>]*)\>/i, "\n" ) - string.gsub!( /\<\/(div|p|pre|blockquote|table|tr)(|\s.+?)\>/i, "\n" ) - string.gsub!( /\<\/td\>/i, ' ' ) + string.gsub!( %r{\<(br|table)(|/| [^>]*)\>}i, "\n" ) + string.gsub!( %r{\}i, "\n" ) + string.gsub!( %r{/}i, ' ' ) # strip all other tags string.gsub!( /\<.+?\>/, '' )