From 2bd01fd107270ea921a5413f2b385fef66ac11f5 Mon Sep 17 00:00:00 2001 From: Peter Hankiewicz Date: Mon, 29 Aug 2022 22:43:59 +0200 Subject: [PATCH] Clean up error log --- app/controllers/token_urls_controller.rb | 2 +- app/models/work.rb | 15 +++++++++++---- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/app/controllers/token_urls_controller.rb b/app/controllers/token_urls_controller.rb index 21f4fe886..0f55ca42a 100644 --- a/app/controllers/token_urls_controller.rb +++ b/app/controllers/token_urls_controller.rb @@ -180,7 +180,7 @@ def disable_documents_notification_errors(token_url) end def token_email_spam? - return true if BlockedTokenUrlDomain.where("'#{@original_email}' ~~* name").any? + return true if BlockedTokenUrlDomain.where('? ~~* name', @original_email).any? begin uri = URI("http://us.stopforumspam.org/api?email=#{@original_email}") diff --git a/app/models/work.rb b/app/models/work.rb index 6367e3db1..8223bb44f 100644 --- a/app/models/work.rb +++ b/app/models/work.rb @@ -78,10 +78,17 @@ def count_by_domain(urls) counted_urls = {} urls.each do |url| - uri = Addressable::URI.parse(url.url) - - # get just domain - domain = uri.host + begin + # Valid URIs + uri = Addressable::URI.parse(url.url) + domain = uri.host + rescue Addressable::URI::InvalidURIError + # Invalid URIs + domain = url.url + .split('/')[2] + .split(' ')[0] + .gsub(/^www\./, '') + end if counted_urls[domain].nil? counted_urls[domain] = {