gpt4 book ai didi

jquery - Ruby Rails、jQuery、Uploadify - 奇怪的 UTF-8 错误

转载 作者:太空宇宙 更新时间:2023-11-03 17:27:54 24 4
gpt4 key购买 nike

我正在我的 Rails 应用程序中设置 jQuery 和 Uploadify(使用 uploadify-rails 插件)。一切正常,闪存已加载,真实性参数与 session key 等一起传递。然而,我的 MySQL 查询处理从闪存上传的方式都报告了“冗余 UTF-8 序列”错误。 SQL 看起来是什么并不重要,只是第一个调用的出现错误:

Processing RoomsController#update to json (for 86.162.102.136 at 2010-04-26 11:27:55) [PUT]
Parameters: {"Filename"=>"fb-logo.png", "_myapp_session"=>"BAh7CzoPc2Vzc2lvbl9pZCIlY2I5N2FjYjQ4ZjcwMmQzMzQxMjIwMmRmN2EwM2ZhZWM6EWludmFsaWRfdXNlckY6EF9jc3JmX3Rva2VuIjEzSWtvaGJrWDNhQXV6OGtuUllyMmdhbkVnR3JKV2QrM3RrVVJZaTJiak1vPToQam9pbl9zb3VyY2UiN2h0dHA6Ly9iZXRhLmNyYXNocGFkZGVyLmNvbS9wcm9maWxlL2V4Y2VsbGVudGxhcmtzIgpmbGFzaElDOidBY3Rpb25Db250cm9sbGVyOjpGbGFzaDo6Rmxhc2hIYXNoewAGOgpAdXNlZHsAOgx1c2VyX2lkaQY=--52b594041395bf8cf5998859eb43c4ed82c74490", "format"=>"json", "folder"=>"/rooms/", "action"=>"update", "authenticity_token"=>"3IkohkX3aAuz8knRYr2ganEgGrJWd 3tkURYi2bjMo=", "_method"=>"PUT", "id"=>"2120", "Upload"=>"Submit Query", "fileext"=>"*.jpg;*.jpeg;*.gif;*.png", "controller"=>"rooms", "room"=>{"photo_uploads"=>#<File:/tmp/RackMultipart20100426-1152-12dn5rn-0>}}
[4;36;1mUser Load (0.0ms)[0m [0;1mArgumentError: redundant UTF-8 sequence: SELECT * FROM `users` WHERE (`users`.`id` = 1) LIMIT 1[0m

ActiveRecord::StatementInvalid (ArgumentError: redundant UTF-8 sequence: SELECT * FROM `users` WHERE (`users`.`id` = 1) LIMIT 1):
lib/authenticated_system.rb:109:in `login_from_session'
lib/authenticated_system.rb:12:in `current_user'
app/controllers/application_controller.rb:296:in `setup_page_titles'
lib/redis_db_logging.rb:18:in `enable_redis_logging'
lib/redis_logger.rb:43:in `redisize'
lib/redis_logger.rb:42:in `redisize'
lib/redis_db_logging.rb:11:in `enable_redis_logging'
haml (2.2.2) lib/sass/plugin/rails.rb:19:in `process_without_compass'
/home/crashpaddernew/.gem/ruby/1.8/gems/chriseppstein-compass-0.8.8/lib/compass/app_integration/rails/action_controller.rb:7:in `process'
/dh/passenger/lib/phusion_passenger/rack/request_handler.rb:91:in `process_request'
/dh/passenger/lib/phusion_passenger/abstract_request_handler.rb:206:in `main_loop'
/dh/passenger/lib/phusion_passenger/railz/application_spawner.rb:376:in `start_request_handler'
/dh/passenger/lib/phusion_passenger/railz/application_spawner.rb:334:in `handle_spawn_application'
/dh/passenger/lib/phusion_passenger/utils.rb:182:in `safe_fork'
/dh/passenger/lib/phusion_passenger/railz/application_spawner.rb:332:in `handle_spawn_application'
/dh/passenger/lib/phusion_passenger/abstract_server.rb:351:in `__send__'
/dh/passenger/lib/phusion_passenger/abstract_server.rb:351:in `main_loop'
/dh/passenger/lib/phusion_passenger/abstract_server.rb:195:in `start_synchronously'
/dh/passenger/lib/phusion_passenger/abstract_server.rb:162:in `start'
/dh/passenger/lib/phusion_passenger/railz/application_spawner.rb:213:in `start'
/dh/passenger/lib/phusion_passenger/spawn_manager.rb:261:in `spawn_rails_application'

有谁知道什么是“冗余 UTF-8 序列”错误,以及为什么来自 Flash uploader 的请求会导致它?还是 JSON 有问题?

最佳答案

以防其他人疯狂地在谷歌上搜索“冗余的 UTF-8 序列”(可能是因为您正试图将 Excel 文档上传到 Rails 应用程序),让我为您省事。

A fix has been implemented in the 3-2-stable branch of rails , 但尚未发布。为了将这种优点应用到您自己的应用程序中,只需创建此文件:

module ActiveSupport::JSON::Encoding
def self.escape(string)
if string.respond_to?(:force_encoding)
string = string.encode(::Encoding::UTF_8, :undef => :replace).force_encoding(::Encoding::BINARY)
end
json = string.gsub(escape_regex) { |s| ESCAPED_CHARS[s] }
json = %("#{json}")
json.force_encoding(::Encoding::UTF_8) if json.respond_to?(:force_encoding)
json
end
end

...并确保要求它。在那之后你应该可以走了。

关于jquery - Ruby Rails、jQuery、Uploadify - 奇怪的 UTF-8 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2713105/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com