プロジェクト

全般

プロフィール

Vote #71600

完了

WikiContent::Version#text return string with #<Encoding:ASCII-8BIT> when uncompressed

Admin Redmine さんが4年以上前に追加. 4年以上前に更新.

ステータス:
Closed
優先度:
通常
担当者:
-
カテゴリ:
Wiki_1
対象バージョン:
開始日:
2022/05/09
期日:
進捗率:

0%

予定工数:
category_id:
1
version_id:
40
issue_org_id:
10590
author_id:
3231
assigned_to_id:
0
comments:
10
status_id:
5
tracker_id:
1
plus1:
0
affected_version:
closed_on:
affected_version_id:
ステータス-->[Closed]

説明

  • ruby 1.9.3p125
  • postgresql 8.4.11
  • rails 2.3.14
  • redmine trunk

Wiki history compression: none

$ script/console 
Loading development environment (Rails 2.3.14)
/home/asor/.rvm/gems/ruby-1.9.3-p125-fast/gems/activesupport-2.3.14/lib/active_support/inflector.rb:3:in `': iconv will be deprecated in the future, use String#encode instead.
NOTE: Gem.source_index is deprecated, use Specification. It will be removed on or after 2011-11-01.
Gem.source_index called from /home/asor/.rvm/gems/ruby-1.9.3-p125-fast/gems/rails-2.3.14/lib/rails/gem_dependency.rb:21.
>> WikiPage.find(:first).content.text.encoding
=> #
>> WikiPage.find(:first).content.versions.first.text.encoding
=> #

We should always force_encoding to UTF-8, if data stored as binary type.
The patch attached.

When applied:

>> WikiPage.find(:first).content.text.encoding
=> #
>> WikiPage.find(:first).content.versions.first.text.encoding
=> #

journals

What database do you use?
mysql1 has problems on Ruby1.9.
You need to use mysql2 instead of mysql1.
source:trunk/Gemfile@9244#L44

--------------------------------------------------------------------------------
Sorry, in description "postgresql 8.4.11".
--------------------------------------------------------------------------------
Patch is (in attachment):
<pre><code class="diff">
commit b0ec4111730809bc2f4bafd071ba2271e290e9e1
Author: Alex Eagle <eagle.alex@gmail.com>
Date: Tue Apr 3 11:58:05 2012 +0400

Force encoding string from data binary always (not only compressed)

diff --git a/app/models/wiki_content.rb b/app/models/wiki_content.rb
index 430e9a5..d5a3870 100644
--- a/app/models/wiki_content.rb
+++ b/app/models/wiki_content.rb
@@ -91,14 +91,16 @@ class WikiContent < ActiveRecord::Base
end

def text
- @text ||= case compression
- when 'gzip'
- str = Zlib::Inflate.inflate(data)
+ @text ||= begin
+ str = case compression
+ when 'gzip'
+ Zlib::Inflate.inflate(data)
+ else
+ # uncompressed data
+ data
+ end
str.force_encoding("UTF-8") if str.respond_to?(:force_encoding)
str
- else
- # uncompressed data
- data
end
end
</code></pre>
--------------------------------------------------------------------------------
It seems acts_as_versioned or PostgreSQL problem.
--------------------------------------------------------------------------------
Not PostgreSQL exactly.
DB return byte-array. Rails interpretate column (t.column :data, :binary) in string context as ASCII-8BIT unless otherwise.
Соde for transformation field 'data' into text defined in WikiContent::Version#text.
IMHO, this is model Version problem.

--------------------------------------------------------------------------------
Might be tied to #6941; I just saw I had this old issue back and that upgrading @pg@ gem to latest version in @Gemfile@ (+@bundle update@) solved it.
--------------------------------------------------------------------------------
Updated pg gem to pg (0.13.2) do not solve it.

<pre>
$ cat Gemfile|grep pg
gem "pg"#, "~> 0.9.0"
$ cat Gemfile.lock|grep pg
pg (0.13.2)
pg
</pre>

Result:

<pre>
>> WikiPage.first.content.versions.last.data.encoding
=> #<Encoding:ASCII-8BIT>
</pre>

--------------------------------------------------------------------------------
Potential release blocker.

Aside note: as explained above, required @pg@ gem version should be raised to prevent #6941.
--------------------------------------------------------------------------------

--------------------------------------------------------------------------------
Patch applied in r9329.
--------------------------------------------------------------------------------

Admin Redmine さんが4年以上前に更新

  • カテゴリWiki_1 にセット
  • 対象バージョン1.4.0_40 にセット

他の形式にエクスポート: Atom PDF

いいね!0
いいね!0