Browse Source

Fixed broken .casecmp rubocop replacements and disabled cop.

Thorsten Eckel 9 years ago
parent
commit
3a401247f5
3 changed files with 9 additions and 3 deletions
  1. 6 0
      .rubocop.yml
  2. 2 2
      app/models/channel/email_parser.rb
  3. 1 1
      lib/encode.rb

+ 6 - 0
.rubocop.yml

@@ -201,3 +201,9 @@ Lint/UselessAssignment:
 Style/ExtraSpacing:
   Description: 'Do not use unnecessary spacing.'
   Enabled: false
+
+# Broken!!!! Generates broken code since "String".downcase == "strinG".downcase is not equals "String".casecmp("strinG") but "String".casecmp("strinG") == 0 !!!
+Performance/Casecmp:
+  Description: 'Use `casecmp` rather than `downcase ==`.'
+  Reference: 'https://github.com/JuanitoFatas/fast-ruby#stringcasecmp-vs-stringdowncase---code'
+  Enabled: false

+ 2 - 2
app/models/channel/email_parser.rb

@@ -193,7 +193,7 @@ class Channel::EmailParser
     # not multipart email
 
     # text part only
-    elsif !mail.mime_type || mail.mime_type.to_s == '' || mail.mime_type.to_s.casecmp('text/plain')
+    elsif !mail.mime_type || mail.mime_type.to_s == '' || mail.mime_type.to_s.casecmp('text/plain') == 0
       data[:body] = mail.body.decoded
       data[:body] = Encode.conv(mail.charset, data[:body])
 
@@ -204,7 +204,7 @@ class Channel::EmailParser
     # html part only, convert to text and add it as attachment
     else
       filename = '-no name-'
-      if mail.mime_type.to_s.casecmp('text/html')
+      if mail.mime_type.to_s.casecmp('text/html') == 0
         filename = 'message.html'
         data[:body] = mail.body.decoded
         data[:body] = Encode.conv(mail.charset, data[:body])

+ 1 - 1
lib/encode.rb

@@ -11,7 +11,7 @@ module Encode
     end
 
     # validate already existing utf8 strings
-    if charset.casecmp('utf8') || charset.casecmp('utf-8')
+    if charset.casecmp('utf8') == 0 || charset.casecmp('utf-8') == 0
       begin
 
         # return if encoding is valid