Allow for split(",") returning nil (#3424)

This commit is contained in:
Yuki Izumi
2017-01-10 11:44:24 +11:00
committed by GitHub
parent 93dcb61742
commit 5d09fb67dd
2 changed files with 12 additions and 1 deletions

View File

@@ -215,7 +215,14 @@ module Linguist
# Returns the Language or nil if none was found.
def self.[](name)
return nil if name.to_s.empty?
name && (@index[name.downcase] || @index[name.split(',').first.downcase])
lang = @index[name.downcase]
return lang if lang
name = name.split(',').first
return nil if name.to_s.empty?
@index[name.downcase]
end
# Public: A List of popular languages

View File

@@ -460,4 +460,8 @@ class TestLanguage < Minitest::Test
assert !language.color, "Unused colour assigned to #{language.name}"
end
end
def test_non_crash_on_comma
assert_nil Language[',']
end
end