mirror of
https://github.com/KevinMidboe/linguist.git
synced 2025-12-08 20:38:47 +00:00
Merge pull request #2549 from github/name-checkin
Don't blow up if empty string/nil passed to alias methods
This commit is contained in:
@@ -150,6 +150,7 @@ module Linguist
|
|||||||
#
|
#
|
||||||
# Returns the Language or nil if none was found.
|
# Returns the Language or nil if none was found.
|
||||||
def self.find_by_name(name)
|
def self.find_by_name(name)
|
||||||
|
return nil if name.to_s.empty?
|
||||||
name && (@name_index[name.downcase] || @name_index[name.split(',').first.downcase])
|
name && (@name_index[name.downcase] || @name_index[name.split(',').first.downcase])
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -164,6 +165,7 @@ module Linguist
|
|||||||
#
|
#
|
||||||
# Returns the Language or nil if none was found.
|
# Returns the Language or nil if none was found.
|
||||||
def self.find_by_alias(name)
|
def self.find_by_alias(name)
|
||||||
|
return nil if name.to_s.empty?
|
||||||
name && (@alias_index[name.downcase] || @alias_index[name.split(',').first.downcase])
|
name && (@alias_index[name.downcase] || @alias_index[name.split(',').first.downcase])
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -275,6 +275,11 @@ class TestLanguage < Minitest::Test
|
|||||||
assert_equal Language['Rust'], Language.find_by_alias('rust,no_run')
|
assert_equal Language['Rust'], Language.find_by_alias('rust,no_run')
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_doesnt_blow_up_with_blank_lookup
|
||||||
|
assert_equal nil, Language.find_by_alias('')
|
||||||
|
assert_equal nil, Language.find_by_name(nil)
|
||||||
|
end
|
||||||
|
|
||||||
def test_name
|
def test_name
|
||||||
assert_equal 'Perl', Language['Perl'].name
|
assert_equal 'Perl', Language['Perl'].name
|
||||||
assert_equal 'Python', Language['Python'].name
|
assert_equal 'Python', Language['Python'].name
|
||||||
|
|||||||
Reference in New Issue
Block a user