From: Tom Hughes Date: Tue, 26 Mar 2019 19:12:18 +0000 (+0000) Subject: Prefer String#match? over butt ugly Regexp#match? X-Git-Tag: live~3245^2 X-Git-Url: https://git.openstreetmap.org./rails.git/commitdiff_plain/d6af4450d1ea3599cdce6921138155f73e154816 Prefer String#match? over butt ugly Regexp#match? --- diff --git a/app/controllers/geocoder_controller.rb b/app/controllers/geocoder_controller.rb index 1270a3274..d9b56147f 100644 --- a/app/controllers/geocoder_controller.rb +++ b/app/controllers/geocoder_controller.rb @@ -17,11 +17,11 @@ class GeocoderController < ApplicationController @sources.push "osm_nominatim_reverse" @sources.push "geonames_reverse" if defined?(GEONAMES_USERNAME) elsif @params[:query] - if /^\d{5}(-\d{4})?$/.match?(@params[:query]) + if @params[:query].match?(/^\d{5}(-\d{4})?$/) @sources.push "osm_nominatim" - elsif /^(GIR 0AA|[A-PR-UWYZ]([0-9]{1,2}|([A-HK-Y][0-9]|[A-HK-Y][0-9]([0-9]|[ABEHMNPRV-Y]))|[0-9][A-HJKS-UW])\s*[0-9][ABD-HJLNP-UW-Z]{2})$/i.match?(@params[:query]) + elsif @params[:query].match?(/^(GIR 0AA|[A-PR-UWYZ]([0-9]{1,2}|([A-HK-Y][0-9]|[A-HK-Y][0-9]([0-9]|[ABEHMNPRV-Y]))|[0-9][A-HJKS-UW])\s*[0-9][ABD-HJLNP-UW-Z]{2})$/i) @sources.push "osm_nominatim" - elsif /^[A-Z]\d[A-Z]\s*\d[A-Z]\d$/i.match?(@params[:query]) + elsif @params[:query].match?(/^[A-Z]\d[A-Z]\s*\d[A-Z]\d$/i) @sources.push "ca_postcode" @sources.push "osm_nominatim" else diff --git a/app/helpers/browse_tags_helper.rb b/app/helpers/browse_tags_helper.rb index e25df03ed..90e75e90a 100644 --- a/app/helpers/browse_tags_helper.rb +++ b/app/helpers/browse_tags_helper.rb @@ -120,7 +120,7 @@ module BrowseTagsHelper # # Also accepting / as a visual separator although not given in RFC 3966, # because it is used as a visual separator in OSM data in some countries. - if %r{^\s*\+[\d\s\(\)/\.-]{6,25}\s*(;\s*\+[\d\s\(\)/\.-]{6,25}\s*)*$}.match?(value) + if value.match?(%r{^\s*\+[\d\s\(\)/\.-]{6,25}\s*(;\s*\+[\d\s\(\)/\.-]{6,25}\s*)*$}) return value.split(";").map do |phone_number| # for display, remove leading and trailing whitespace phone_number = phone_number.strip diff --git a/lib/password_hash.rb b/lib/password_hash.rb index 5bafe6dda..9f77fdc0d 100644 --- a/lib/password_hash.rb +++ b/lib/password_hash.rb @@ -18,7 +18,7 @@ module PasswordHash def self.check(hash, salt, candidate) if salt.nil? candidate = Digest::MD5.hexdigest(candidate) - elsif /!/.match?(salt) + elsif salt.match?(/!/) algorithm, iterations, salt = salt.split("!") size = Base64.strict_decode64(hash).length candidate = self.hash(candidate, salt, iterations.to_i, size, algorithm) @@ -32,7 +32,7 @@ module PasswordHash def self.upgrade?(hash, salt) if salt.nil? return true - elsif /!/.match?(salt) + elsif salt.match?(/!/) algorithm, iterations, salt = salt.split("!") return true if Base64.strict_decode64(salt).length != SALT_BYTE_SIZE return true if Base64.strict_decode64(hash).length != HASH_BYTE_SIZE