mirror of
https://github.com/atom/atom.git
synced 2026-01-22 21:38:10 -05:00
Guard against missing file path in getScore()
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
* Fixed: Error selecting a grammar for an untitled editor
|
||||
|
||||
* Added: j/k now can be used to navigate the tree view and archive editor
|
||||
|
||||
* Fixed: Atom can now be launched when ~/.atom/config.cson doesn't exist
|
||||
|
||||
@@ -75,6 +75,12 @@ describe "the `syntax` global", ->
|
||||
|
||||
expect(syntax.selectGrammar('more.test', '')).toBe grammar1
|
||||
|
||||
describe "when there is no file path", ->
|
||||
it "does not throw an exception (regression)", ->
|
||||
expect(-> syntax.selectGrammar(null, '#!/usr/bin/ruby')).not.toThrow()
|
||||
expect(-> syntax.selectGrammar(null, '')).not.toThrow()
|
||||
expect(-> syntax.selectGrammar(null, null)).not.toThrow()
|
||||
|
||||
describe ".removeGrammar(grammar)", ->
|
||||
it "removes the grammar, so it won't be returned by selectGrammar", ->
|
||||
grammar = syntax.selectGrammar('foo.js')
|
||||
|
||||
@@ -74,11 +74,10 @@ class TextMateGrammar
|
||||
getScore: (filePath, contents) ->
|
||||
contents = fsUtils.read(filePath) if not contents? and fsUtils.isFileSync(filePath)
|
||||
|
||||
|
||||
if syntax.grammarOverrideForPath(filePath) is @scopeName
|
||||
2 + filePath.length
|
||||
2 + (filePath?.length ? 0)
|
||||
else if @matchesContents(contents)
|
||||
1 + filePath.length
|
||||
1 + (filePath?.length ? 0)
|
||||
else
|
||||
@getPathScore(filePath)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user