Handle empty user agent [skip ci]
Andrew
committed Apr 07, 2018
commit c6e04e6f75a9661a6095dff6c6e904ca4860b855
Showing 1
changed file with
7 additions
and 1 deletions
ahoy/visit_properties.rb b/lib/ahoy/visit_properties.rb
+7
-1
| @@ | @@ -72,7 +72,7 @@ module Ahoy |
| def request_properties | |
| { | |
| ip: request.remote_ip, | |
| - | user_agent: request.user_agent.encode('UTF-8', 'binary', invalid: :replace, undef: :replace, replace: ''), |
| + | user_agent: ensure_utf8(request.user_agent), |
| referrer: referrer, | |
| landing_page: landing_page, | |
| platform: params["platform"], | |
| @@ | @@ -82,5 +82,11 @@ module Ahoy |
| screen_width: params["screen_width"] | |
| } | |
| end | |
| + | |
| + | def ensure_utf8(str) |
| + | if str |
| + | str.encode("UTF-8", "binary", invalid: :replace, undef: :replace, replace: "") |
| + | end |
| + | end |
| end | |
| end | |