From 6ec43e971a9f9afa384d7984ca01d92e668902fe Mon Sep 17 00:00:00 2001 From: Kouhei Sutou Date: Wed, 22 Aug 2012 11:22:30 +0900 Subject: [PATCH] Fix wrong environment variable check MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit LC_CTYPES should be checked instead of LC_MESSAGES. Fix the third report of mutoh/locale#5. Debian bug #520181: http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=520181 Patch by Hleb Valoshka. Thanks!!! Rreported by Adeodato Simó. Thanks!!! --- lib/locale/driver/env.rb | 7 ++++--- lib/locale/driver/posix.rb | 2 +- test/test_detect_general.rb | 11 ++++++----- test/test_driver_jruby.rb | 2 +- test/test_driver_win32.rb | 2 +- 5 files changed, 13 insertions(+), 11 deletions(-) diff --git a/lib/locale/driver/env.rb b/lib/locale/driver/env.rb index d2dab27..b4e96c6 100644 --- a/lib/locale/driver/env.rb +++ b/lib/locale/driver/env.rb @@ -1,6 +1,7 @@ # -*- coding: utf-8 -*- # # Copyright (C) 2012 Kouhei Sutou +# Copyright (C) 2012 Hleb Valoshka # Copyright (C) 2008 Masao Mutoh # # Original: Ruby-GetText-Package-1.92.0. @@ -33,11 +34,11 @@ module Driver module Env module_function - # Gets the locale from environment variable. (LC_ALL > LC_MESSAGES > LANG) + # Gets the locale from environment variable. (LC_ALL > LC_CTYPES > 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_CTYPES"], ENV["LANG"]].each do |loc| if loc != nil and loc.size > 0 return Locale::Tag::Posix.parse(loc) end @@ -45,7 +46,7 @@ def locale nil end - # Gets the locales from environment variables. (LANGUAGE > LC_ALL > LC_MESSAGES > LANG) + # Gets the locales from environment variables. (LANGUAGE > LC_ALL > LC_CTYPES > LANG) # * Returns: an Array of the locale as Locale::Tag::Posix or nil. def locales locales = ENV["LANGUAGE"] diff --git a/lib/locale/driver/posix.rb b/lib/locale/driver/posix.rb index 11838f5..16d8efd 100644 --- a/lib/locale/driver/posix.rb +++ b/lib/locale/driver/posix.rb @@ -30,7 +30,7 @@ module Posix $stderr.puts self.name + " is loaded." if $DEBUG module_function - # Gets the locales from environment variables. (LANGUAGE > LC_ALL > LC_MESSAGES > LANG) + # Gets the locales from environment variables. (LANGUAGE > LC_ALL > LC_CTYPES > LANG) # Only LANGUAGE accept plural languages such as "nl_BE; # * Returns: an Array of the locale as Locale::Tag::Posix or nil. def locales diff --git a/test/test_detect_general.rb b/test/test_detect_general.rb index c83cfd5..ca0af22 100644 --- a/test/test_detect_general.rb +++ b/test/test_detect_general.rb @@ -1,6 +1,7 @@ # -*- coding: utf-8 -*- # # Copyright (C) 2012 Kouhei Sutou +# Copyright (C) 2012 Hleb Valoshka # Copyright (C) 2009-2010 Masao Mutoh # # License: Ruby's or LGPL @@ -27,14 +28,14 @@ def setup Locale.init Locale.clear_all ENV["LC_ALL"] = nil - ENV["LC_MESSAGES"] = nil + ENV["LC_CTYPES"] = 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_CTYPES"] = "zh_CN.UTF-8" #Ignored. ENV["LANG"] = "ko_KR.UTF-8" #Ignored. ENV["LANGUAGE"] = nil @@ -50,7 +51,7 @@ def test_lc_all def test_lc_messages ENV["LC_ALL"] = nil - ENV["LC_MESSAGES"] = "ja_JP.eucJP" + ENV["LC_CTYPES"] = "ja_JP.eucJP" ENV["LANG"] = "ko_KR.UTF-8" #Ignored. ENV["LANGUAGE"] = nil @@ -66,7 +67,7 @@ def test_lc_messages def test_lang ENV["LC_ALL"] = nil - ENV["LC_MESSAGES"] = nil + ENV["LC_CTYPES"] = nil ENV["LANG"] = "ja_JP.eucJP" ENV["LANGUAGE"] = nil @@ -82,7 +83,7 @@ def test_lang def test_lang_complex ENV["LC_ALL"] = "zh_CN.UTF-8" # Ignored. - ENV["LC_MESSAGES"] = "ko_KR.UTF-8" #Ingored. + ENV["LC_CTYPES"] = "ko_KR.UTF-8" #Ingored. ENV["LANG"] = "en_US.UTF-8" # Ignored. ENV["LANGUAGE"] ="ja_JP.eucJP:zh_CN.UTF-8" diff --git a/test/test_driver_jruby.rb b/test/test_driver_jruby.rb index 2df8d6c..27e8e14 100644 --- a/test/test_driver_jruby.rb +++ b/test/test_driver_jruby.rb @@ -26,7 +26,7 @@ class TestDiverJRuby < Test::Unit::TestCase def setup ENV["LC_ALL"] = nil - ENV["LC_MESSAGES"] = nil + ENV["LC_CTYPES"] = nil ENV["LANG"] = nil ENV["LANGUAGE"] = nil end diff --git a/test/test_driver_win32.rb b/test/test_driver_win32.rb index e93ea38..7905913 100644 --- a/test/test_driver_win32.rb +++ b/test/test_driver_win32.rb @@ -6,7 +6,7 @@ class TestDiverWin32 < Test::Unit::TestCase def setup ENV["LC_ALL"] = nil - ENV["LC_MESSAGES"] = nil + ENV["LC_CTYPES"] = nil ENV["LANG"] = nil ENV["LANGUAGE"] = nil Locale::Driver::Win32.set_thread_locale_id(nil)