mirror of
				https://github.com/KevinMidboe/linguist.git
				synced 2025-10-29 17:50:22 +00:00 
			
		
		
		
	Fix failing edges on leading commas in args (#3905)
This commit is contained in:
		| @@ -110,7 +110,7 @@ module Linguist | ||||
|     # Returns the Language or nil if none was found. | ||||
|     def self.find_by_name(name) | ||||
|       return nil if !name.is_a?(String) || name.to_s.empty? | ||||
|       name && (@name_index[name.downcase] || @name_index[name.split(',').first.downcase]) | ||||
|       name && (@name_index[name.downcase] || @name_index[name.split(',', 2).first.downcase]) | ||||
|     end | ||||
|  | ||||
|     # Public: Look up Language by one of its aliases. | ||||
| @@ -125,7 +125,7 @@ module Linguist | ||||
|     # Returns the Language or nil if none was found. | ||||
|     def self.find_by_alias(name) | ||||
|       return nil if !name.is_a?(String) || name.to_s.empty? | ||||
|       name && (@alias_index[name.downcase] || @alias_index[name.split(',').first.downcase]) | ||||
|       name && (@alias_index[name.downcase] || @alias_index[name.split(',', 2).first.downcase]) | ||||
|     end | ||||
|  | ||||
|     # Public: Look up Languages by filename. | ||||
| @@ -219,10 +219,7 @@ module Linguist | ||||
|       lang = @index[name.downcase] | ||||
|       return lang if lang | ||||
|  | ||||
|       name = name.split(',').first | ||||
|       return nil if name.to_s.empty? | ||||
|  | ||||
|       @index[name.downcase] | ||||
|       @index[name.split(',', 2).first.downcase] | ||||
|     end | ||||
|  | ||||
|     # Public: A List of popular languages | ||||
|   | ||||
| @@ -470,5 +470,7 @@ class TestLanguage < Minitest::Test | ||||
|  | ||||
|   def test_non_crash_on_comma | ||||
|     assert_nil Language[','] | ||||
|     assert_nil Language.find_by_name(',') | ||||
|     assert_nil Language.find_by_alias(',') | ||||
|   end | ||||
| end | ||||
|   | ||||
		Reference in New Issue
	
	Block a user