RBoy
(RBoy)
Mai 19, 2024, 1:27
1
Je vois cet avertissement dans les journaux, je ne suis pas sûr de sa provenance. Je ne l’ai jamais vu auparavant, il a commencé après la mise à niveau de la version 3.2.0 à la version 3.3.0.
C’est le seul avertissement autour des horodatages, aucune autre erreur/avertissement (j’ai d’abord pensé que c’était lié aux e-mails, mais je ne vois aucune erreur ou e-mail rejeté à ce moment-là).
Installé
3.3.0.beta2-dev
(777b8f6d51 )
Message (4 copies signalées)
RequestTracker.get_data a échoué : Encoding::UndefinedConversionError : « \xA1 » de ASCII-8BIT vers UTF-8
Trace
/var/www/discourse/lib/middleware/request_tracker.rb:190:in `encode'
/var/www/discourse/lib/middleware/request_tracker.rb:190:in `get_data'
/var/www/discourse/lib/middleware/request_tracker.rb:207:in `log_request_info'
/var/www/discourse/lib/middleware/request_tracker.rb:320:in `call'
/var/www/discourse/vendor/bundle/ruby/3.2.0/gems/railties-7.0.8.1/lib/rails/engine.rb:530:in `call'
/var/www/discourse/vendor/bundle/ruby/3.2.0/gems/railties-7.0.8.1/lib/rails/railtie.rb:226:in `public_send'
/var/www/discourse/vendor/bundle/ruby/3.2.0/gems/railties-7.0.8.1/lib/rails/railtie.rb:226:in `method_missing'
/var/www/discourse/vendor/bundle/ruby/3.2.0/gems/rack-2.2.9/lib/rack/urlmap.rb:74:in `block in call'
/var/www/discourse/vendor/bundle/ruby/3.2.0/gems/rack-2.2.9/lib/rack/urlmap.rb:58:in `each'
/var/www/discourse/vendor/bundle/ruby/3.2.0/gems/rack-2.2.9/lib/rack/urlmap.rb:58:in `call'
/var/www/discourse/vendor/bundle/ruby/3.2.0/gems/unicorn-6.1.0/lib/unicorn/http_server.rb:634:in `process_client'
/var/www/discourse/vendor/bundle/ruby/3.2.0/gems/unicorn-6.1.0/lib/unicorn/http_server.rb:739:in `worker_loop'
/var/www/discourse/vendor/bundle/ruby/3.2.0/gems/unicorn-6.1.0/lib/unicorn/http_server.rb:547:in `spawn_missing_workers'
/var/www/discourse/vendor/bundle/ruby/3.2.0/gems/unicorn-6.1.0/lib/unicorn/http_server.rb:143:in `start'
/var/www/discourse/vendor/bundle/ruby/3.2.0/gems/unicorn-6.1.0/bin/unicorn:128:in `<top (required)>'
/var/www/discourse/vendor/bundle/ruby/3.2.0/bin/unicorn:25:in `load'
/var/www/discourse/vendor/bundle/ruby/3.2.0/bin/unicorn:25:in `<main>'
Il semble y avoir un problème avec un robot d’exploration Web spécifique ; cela ne devrait pas vous affecter.
# This Discourse-Track-View request header is set in `lib/ajax.js`,
# whenever the user navigates between Ember routes, to indicate a
# browser page view.
env_track_view = env["HTTP_DISCOURSE_TRACK_VIEW"]
explicit_track_view = status == 200 && %w[1 true].include?(env_track_view)
# An HTML response to a GET request is tracked implicitly, these do
Ici, il y a un problème avec l’encodage de l’agent utilisateur du robot d’exploration en UTF-8, car il contient un octet invalide.
scrub est censé faire cela. Peut-être que l’utilisation du paramètre :undef peut aider ici :
user_agent.encode("utf-8", :undef => :replace)
[51] pry(main)> string = "hello \xa1\x28world\x29".force_encoding("ASCII-8BIT")
=> "hello \xA1(world)"
[52] pry(main)> string.encode('utf-8')
Encoding::UndefinedConversionError: "\xA1" from ASCII-8BIT to UTF-8
from (pry):52:in `encode'
[53] pry(main)> string.encode('utf-8', :undef => :replace)
=> "hello �(world)"
4 « J'aime »
sam
(Sam Saffron)
Mai 22, 2024, 5:00
3
Ça a l’air bien, une PR ?
2 « J'aime »
Une correction a été fusionnée.
main ← Arkshine:fix-crowler-useragent-encoding
opened 04:29PM - 24 May 24 UTC
Meta: https://meta.discourse.org/t/encoding-conversion-error-from-ascii-8bit-to-… utf-8-in-logs/308603/2
Crawler requests for non-UTF-8 user agents that contain invalid bytes generate an exception at two places.
See [`get_data()`](https://github.com/discourse/discourse/blob/main/lib/middleware/request_tracker.rb#L158-L193) function:
* On `encode("utf-8")` that results either in the following error depending on the incoming encoding
* `InvalidByteSequenceError`
* `UndefinedConversionError`
* On matching user-agent with invalid byte results to `ArgumentError`.
_Called from `helper.is_crawler` and `helper.is_mobile`, part of the `AnonymousCache::Helper` class._
This PR does the following:
* Handles `encode()` exceptions by relying on `undef` and `invalid` params to replace the faulty bytes instead of raising an exception. It moved into its own module.
* Provides a safe user agent in `AnonymousCache::Helper.`
The `anonymous_cache_spec.rb` tests are specifically for the methods: `blocked_crawler?`, `key_is_modern_mobile_device?`, and `key_is_old_browser?`.
Hopefully, the implementation is okay.
4 « J'aime »
Ce sujet a été automatiquement fermé après 3 jours. Les nouvelles réponses ne sont plus autorisées.