aboutsummaryrefslogtreecommitdiffstats
path: root/Library
diff options
context:
space:
mode:
authorVítor Galvão2017-09-29 19:23:50 +0100
committerGitHub2017-09-29 19:23:50 +0100
commit03e37faea47c0e4edb41e41c44ebe0ca45960421 (patch)
treeff4745a35c654107d6251a4d57bdb17d43e9d384 /Library
parent60a8b29a41da79c1622cf5c55fd79a7976a60abe (diff)
parent479544665b9e6edf66c7add1eb6b3c98d98de384 (diff)
downloadbrew-03e37faea47c0e4edb41e41c44ebe0ca45960421.tar.bz2
Merge pull request #3234 from reitermarkus/locale
Support UN M.49 region codes.
Diffstat (limited to 'Library')
-rw-r--r--Library/Homebrew/locale.rb6
-rw-r--r--Library/Homebrew/test/locale_spec.rb4
2 files changed, 7 insertions, 3 deletions
diff --git a/Library/Homebrew/locale.rb b/Library/Homebrew/locale.rb
index d918e2a2a..c430d11b6 100644
--- a/Library/Homebrew/locale.rb
+++ b/Library/Homebrew/locale.rb
@@ -2,9 +2,9 @@ class Locale
class ParserError < StandardError
end
- LANGUAGE_REGEX = /(?:[a-z]{2,3})/ # ISO 639-1 or ISO 639-2
- REGION_REGEX = /(?:[A-Z]{2})/ # ISO 3166-1
- SCRIPT_REGEX = /(?:[A-Z][a-z]{3})/ # ISO 15924
+ LANGUAGE_REGEX = /(?:[a-z]{2,3})/ # ISO 639-1 or ISO 639-2
+ REGION_REGEX = /(?:[A-Z]{2}|\d{3})/ # ISO 3166-1 or UN M.49
+ SCRIPT_REGEX = /(?:[A-Z][a-z]{3})/ # ISO 15924
LOCALE_REGEX = /\A((?:#{LANGUAGE_REGEX}|#{REGION_REGEX}|#{SCRIPT_REGEX})(?:\-|$)){1,3}\Z/
diff --git a/Library/Homebrew/test/locale_spec.rb b/Library/Homebrew/test/locale_spec.rb
index 9e4d09e83..9c684f0e7 100644
--- a/Library/Homebrew/test/locale_spec.rb
+++ b/Library/Homebrew/test/locale_spec.rb
@@ -9,6 +9,10 @@ describe Locale do
expect(described_class.parse("zh-CN-Hans")).to eql(described_class.new("zh", "CN", "Hans"))
end
+ it "correctly parses a string with a UN M.49 region code" do
+ expect(described_class.parse("es-419")).to eql(described_class.new("es", "419", nil))
+ end
+
context "raises a ParserError when given" do
it "an empty string" do
expect { described_class.parse("") }.to raise_error(Locale::ParserError)