From 12580bce83926c7ad6535bfa9d85559f0cd951b3 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Wed, 10 Jul 2013 08:54:15 -0700 Subject: [PATCH] Guard against missing file path in getScore() --- CHANGELOG.md | 2 ++ spec/app/syntax-spec.coffee | 6 ++++++ src/app/text-mate-grammar.coffee | 5 ++--- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 37ce8e2e9..b642ddc91 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/spec/app/syntax-spec.coffee b/spec/app/syntax-spec.coffee index 497bb88ff..0cca30ed1 100644 --- a/spec/app/syntax-spec.coffee +++ b/spec/app/syntax-spec.coffee @@ -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') diff --git a/src/app/text-mate-grammar.coffee b/src/app/text-mate-grammar.coffee index 5796631b0..ce5e0c60b 100644 --- a/src/app/text-mate-grammar.coffee +++ b/src/app/text-mate-grammar.coffee @@ -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)