Guard against missing file path in getScore()

This commit is contained in:
Kevin Sawicki
2013-07-10 08:54:15 -07:00
parent 753b11cf15
commit 12580bce83
3 changed files with 10 additions and 3 deletions

View File

@@ -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

View File

@@ -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')

View File

@@ -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)