Skip to content

Commit 918a412

Browse files
committed
use String#casecmp for case insensitive comparison (#20369)
Contributed by Go MAEDA. git-svn-id: http://svn.redmine.org/redmine/trunk@14484 e93f8b46-1217-0410-a6f0-8f06a7374b81
1 parent 039c333 commit 918a412

File tree

6 files changed

+12
-11
lines changed

6 files changed

+12
-11
lines changed

app/controllers/account_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ def lost_password
102102
token = Token.new(:user => user, :action => "recovery")
103103
if token.save
104104
# Don't use the param to send the email
105-
recipent = user.mails.detect {|e| e.downcase == email.downcase} || user.mail
105+
recipent = user.mails.detect {|e| email.casecmp(e) == 0} || user.mail
106106
Mailer.lost_password(token, recipent).deliver
107107
flash[:notice] = l(:notice_account_lost_email_sent)
108108
redirect_to signin_path

app/helpers/application_helper.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -609,7 +609,7 @@ def parse_non_pre_blocks(text, obj, macros)
609609
parsed << text
610610
if tag
611611
if closing
612-
if tags.last == tag.downcase
612+
if tags.last.casecmp(tag) == 0
613613
tags.pop
614614
end
615615
else

app/models/custom_field.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ def value_from_keyword(keyword, customized)
144144
possible_values_options = possible_values_options(customized)
145145
if possible_values_options.present?
146146
keyword = keyword.to_s.downcase
147-
if v = possible_values_options.detect {|text, id| text.downcase == keyword}
147+
if v = possible_values_options.detect {|text, id| keyword.casecmp(text) == 0}
148148
if v.is_a?(Array)
149149
v.last
150150
else

app/models/mail_handler.rb

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ def receive(email, options={})
9292
@handler_options = options
9393
sender_email = email.from.to_a.first.to_s.strip
9494
# Ignore emails received from the application emission address to avoid hell cycles
95-
if sender_email.downcase == Setting.mail_from.to_s.strip.downcase
95+
if sender_email.casecmp(Setting.mail_from.to_s.strip) == 0
9696
if logger
9797
logger.info "MailHandler: ignoring email from Redmine emission address [#{sender_email}]"
9898
end
@@ -547,18 +547,19 @@ def find_assignee_from_keyword(keyword, issue)
547547
assignable = issue.assignable_users
548548
assignee = nil
549549
assignee ||= assignable.detect {|a|
550-
a.mail.to_s.downcase == keyword ||
551-
a.login.to_s.downcase == keyword
550+
keyword.casecmp(a.mail.to_s) == 0 ||
551+
keyword.casecmp(a.login.to_s) == 0
552552
}
553553
if assignee.nil? && keyword.match(/ /)
554554
firstname, lastname = *(keyword.split) # "First Last Throwaway"
555555
assignee ||= assignable.detect {|a|
556-
a.is_a?(User) && a.firstname.to_s.downcase == firstname &&
557-
a.lastname.to_s.downcase == lastname
556+
a.is_a?(User) &&
557+
firstname.casecmp(a.firstname.to_s) == 0 &&
558+
lastname.casecmp(a.lastname.to_s) == 0
558559
}
559560
end
560561
if assignee.nil?
561-
assignee ||= assignable.detect {|a| a.name.downcase == keyword}
562+
assignee ||= assignable.detect {|a| keyword.casecmp(a.name) == 0}
562563
end
563564
assignee
564565
end

app/models/principal.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ def <=>(principal)
130130
if principal.nil?
131131
-1
132132
elsif self.class.name == principal.class.name
133-
self.to_s.downcase <=> principal.to_s.downcase
133+
self.to_s.casecmp(principal.to_s)
134134
else
135135
# groups after users
136136
principal.class.name <=> self.class.name

app/models/project.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -531,7 +531,7 @@ def project
531531
end
532532

533533
def <=>(project)
534-
name.downcase <=> project.name.downcase
534+
name.casecmp(project.name)
535535
end
536536

537537
def to_s

0 commit comments

Comments
 (0)