FIX: crawler requests exceptions for non UTF-8 user agents with invalid bytes

This commit is contained in:
Arkshine
2024-05-24 03:49:17 +02:00
committed by Régis Hanol
parent b757275c1e
commit 1fffb236b2
5 changed files with 86 additions and 13 deletions

View File

@ -0,0 +1,14 @@
# frozen_string_literal: true
module HttpUserAgentEncoder
def self.ensure_utf8(user_agent)
return "" unless user_agent
if user_agent.encoding != Encoding::UTF_8
user_agent = user_agent.encode("utf-8", invalid: :replace, undef: :replace)
user_agent.scrub!
end
user_agent || ""
end
end