Package: ruby-locale / 2.0.5-6

0004-fix-bugs-with-charset-handling.patch Patch series | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
From: Hleb Valoshka <375GNU@Gmail.COM>
Date: Wed, 22 Aug 2012 11:36:29 +0300
Subject: fix bugs with charset handling

   Fixes #520181
---
 lib/locale/driver/env.rb    |    4 ++--
 lib/locale/tag/posix.rb     |   23 ++++++++++++++++-------
 lib/locale/taglist.rb       |    6 +-----
 test/test_detect_general.rb |   10 +++++-----
 4 files changed, 24 insertions(+), 19 deletions(-)

diff --git a/lib/locale/driver/env.rb b/lib/locale/driver/env.rb
index 3d08500..78df8c5 100644
--- a/lib/locale/driver/env.rb
+++ b/lib/locale/driver/env.rb
@@ -24,11 +24,11 @@ module Locale
     module Env
       module_function
 
-      # Gets the locale from environment variable. (LC_ALL > LC_MESSAGES > LANG)
+      # Gets the locale from environment variable. (LC_ALL > LC_CTYPE > LANG)
       # Returns: the locale as Locale::Tag::Posix.
       def locale
         # At least one environment valiables should be set on *nix system.
-        [ENV["LC_ALL"], ENV["LC_MESSAGES"], ENV["LANG"]].each do |loc|
+        [ENV["LC_ALL"], ENV["LC_CTYPE"], ENV["LANG"]].each do |loc|
           if loc != nil and loc.size > 0
             return Locale::Tag::Posix.parse(loc)
           end
diff --git a/lib/locale/tag/posix.rb b/lib/locale/tag/posix.rb
index b04aa54..1ce944a 100644
--- a/lib/locale/tag/posix.rb
+++ b/lib/locale/tag/posix.rb
@@ -30,9 +30,9 @@ module Locale
       end
 
       def self.parse(tag)
-        if tag =~ /^(C|POSIX)$/
-          ret = self.new("en", "US")
-          ret.tag = tag
+        if tag =~ /\A(C|POSIX)(?:\.([^@]+))?\Z/
+          ret = self.new("en", "US", $2)
+          ret.tag = $1
           ret
         elsif tag =~ TAG_RE
           ret = self.new($1, $2, $3, $4)
@@ -47,10 +47,15 @@ module Locale
       #   <language>_<COUNTRY>.<CHARSET>@<MODIFIER>
       #   (e.g.) "ja_JP.EUC-JP@Modifier"
       def to_s
-        s = @language.dup
-        s << "_#{@region}" if @region
-        s << ".#{@charset}" if @charset
-        s << "@#{@modifier}" if @modifier
+        if posix?
+          s = tag.dup
+          s << ".#{@charset}" if @charset
+        else
+          s = @language.dup
+          s << "_#{@region}" if @region
+          s << ".#{@charset}" if @charset
+          s << "@#{@modifier}" if @modifier
+        end
         s
       end
 
@@ -92,6 +97,10 @@ module Locale
         end
       end
 
+      def posix?
+        ['POSIX', 'C'].include? tag
+      end
+
     end
   end
 end
diff --git a/lib/locale/taglist.rb b/lib/locale/taglist.rb
index e5d879c..2b6c8e7 100644
--- a/lib/locale/taglist.rb
+++ b/lib/locale/taglist.rb
@@ -46,11 +46,7 @@ module Locale
     end
     # Returns the top priority charset. (posix)
     def charset
-      if self[0].respond_to? :charset
-        self[0].charset
-      else
-        ::Locale.driver_module.charset
-      end
+      self[0].respond_to?(:charset) and self[0].charset or ::Locale.driver_module.charset
     end
     memoize :charset
 
diff --git a/test/test_detect_general.rb b/test/test_detect_general.rb
index 08b912d..ab71857 100644
--- a/test/test_detect_general.rb
+++ b/test/test_detect_general.rb
@@ -6,14 +6,14 @@ class TestDetectGeneral < Test::Unit::TestCase
   def setup
     Locale.clear_all
     ENV["LC_ALL"] = nil
-    ENV["LC_MESSAGES"] = nil
+    ENV["LC_CTYPE"] = nil
     ENV["LANG"] = nil
     ENV["LANGUAGE"] = nil
   end
 
   def test_lc_all
     ENV["LC_ALL"] = "ja_JP.eucJP"
-    ENV["LC_MESSAGES"] = "zh_CN.UTF-8"  #Ignored.
+    ENV["LC_CTYPE"] = "zh_CN.UTF-8"  #Ignored.
     ENV["LANG"] = "ko_KR.UTF-8"  #Ignored.
     ENV["LANGUAGE"] = nil
 
@@ -29,7 +29,7 @@ class TestDetectGeneral < Test::Unit::TestCase
 
   def test_lc_messages
     ENV["LC_ALL"] = nil
-    ENV["LC_MESSAGES"] = "ja_JP.eucJP"
+    ENV["LC_CTYPE"] = "ja_JP.eucJP"
     ENV["LANG"] = "ko_KR.UTF-8"  #Ignored.
     ENV["LANGUAGE"] = nil
 
@@ -45,7 +45,7 @@ class TestDetectGeneral < Test::Unit::TestCase
 
   def test_lang
     ENV["LC_ALL"] = nil
-    ENV["LC_MESSAGES"] = nil
+    ENV["LC_CTYPE"] = nil
     ENV["LANG"] = "ja_JP.eucJP"
     ENV["LANGUAGE"] = nil
 
@@ -61,7 +61,7 @@ class TestDetectGeneral < Test::Unit::TestCase
 
   def test_lang_complex
     ENV["LC_ALL"] = "zh_CN.UTF-8"  # Ignored.
-    ENV["LC_MESSAGES"] = "ko_KR.UTF-8" #Ingored.
+    ENV["LC_CTYPE"] = "ko_KR.UTF-8" #Ingored.
     ENV["LANG"] = "en_US.UTF-8"  # Ignored.
     ENV["LANGUAGE"] ="ja_JP.eucJP:zh_CN.UTF-8"