summaryrefslogtreecommitdiffstats
path: root/lib/redmine/field_format.rb
diff options
context:
space:
mode:
authorGo MAEDA <maeda@farend.jp>2019-03-27 02:15:24 +0000
committerGo MAEDA <maeda@farend.jp>2019-03-27 02:15:24 +0000
commit72e1451159206af1c335b23e0c1e5bf9ed84bc85 (patch)
tree598902ed0066c4b292a6c1612aad4b203cbb81de /lib/redmine/field_format.rb
parentf0d579adebfe3c5da93135fbaa3d9ec503d06855 (diff)
downloadredmine-72e1451159206af1c335b23e0c1e5bf9ed84bc85.tar.gz
redmine-72e1451159206af1c335b23e0c1e5bf9ed84bc85.zip
Use Regexp#match? to reduce allocations of MatchData object (#28940).
Patch by Pavel Rosický. git-svn-id: http://svn.redmine.org/redmine/trunk@18011 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'lib/redmine/field_format.rb')
-rw-r--r--lib/redmine/field_format.rb12
1 files changed, 6 insertions, 6 deletions
diff --git a/lib/redmine/field_format.rb b/lib/redmine/field_format.rb
index e1aba49f5..3d8a976fc 100644
--- a/lib/redmine/field_format.rb
+++ b/lib/redmine/field_format.rb
@@ -251,7 +251,7 @@ module Redmine
[text, url]
end
links = texts_and_urls.sort_by(&:first).map do |text, url|
- css_class = (url =~ /^https?:\/\//) ? 'external' : nil
+ css_class = (/^https?:\/\//.match?(url)) ? 'external' : nil
view.link_to_if uri_with_safe_scheme?(url), text, url, :class => css_class
end
links.join(', ').html_safe
@@ -360,7 +360,7 @@ module Redmine
def validate_single_value(custom_field, value, customized=nil)
errs = super
value = value.to_s
- unless custom_field.regexp.blank? or value =~ Regexp.new(custom_field.regexp)
+ unless custom_field.regexp.blank? or Regexp.new(custom_field.regexp).match?(value)
errs << ::I18n.t('activerecord.errors.messages.invalid')
end
if custom_field.min_length && value.length < custom_field.min_length
@@ -442,12 +442,12 @@ module Redmine
url = url_from_pattern(custom_field, value, customized)
else
url = value.to_s
- unless url =~ %r{\A[a-z]+://}i
+ unless %r{\A[a-z]+://}i.match?(url)
# no protocol found, use http by default
url = "http://" + url
end
end
- css_class = (url =~ /^https?:\/\//) ? 'external' : nil
+ css_class = (/^https?:\/\//.match?(url)) ? 'external' : nil
view.link_to value.to_s.truncate(40), url, :class => css_class
else
value.to_s
@@ -492,7 +492,7 @@ module Redmine
def validate_single_value(custom_field, value, customized=nil)
errs = super
- errs << ::I18n.t('activerecord.errors.messages.not_a_number') unless value.to_s.strip =~ /^[+-]?\d+$/
+ errs << ::I18n.t('activerecord.errors.messages.not_a_number') unless /^[+-]?\d+$/.match?(value.to_s.strip)
errs
end
@@ -536,7 +536,7 @@ module Redmine
end
def validate_single_value(custom_field, value, customized=nil)
- if value =~ /^\d{4}-\d{2}-\d{2}$/ && (value.to_date rescue false)
+ if /^\d{4}-\d{2}-\d{2}$/.match?(value) && (value.to_date rescue false)
[]
else
[::I18n.t('activerecord.errors.messages.not_a_date')]