From 3a401247f564e2dbd7f400d3373c591c37722988 Mon Sep 17 00:00:00 2001 From: Thorsten Eckel Date: Fri, 15 Jan 2016 22:17:05 +0100 Subject: [PATCH] Fixed broken .casecmp rubocop replacements and disabled cop. --- .rubocop.yml | 6 ++++++ app/models/channel/email_parser.rb | 4 ++-- lib/encode.rb | 2 +- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index 61171d89e..bbe11ff67 100644 --- a/.rubocop.yml +++ b/.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 \ No newline at end of file diff --git a/app/models/channel/email_parser.rb b/app/models/channel/email_parser.rb index 660c117b5..f9a835296 100644 --- a/app/models/channel/email_parser.rb +++ b/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]) diff --git a/lib/encode.rb b/lib/encode.rb index be484c50c..79b3a2c53 100644 --- a/lib/encode.rb +++ b/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