From 4df6d4f705b0beb50e0588730fa533c671f8e3ce Mon Sep 17 00:00:00 2001 From: Ben Gotow Date: Thu, 6 Aug 2015 13:59:30 -0700 Subject: [PATCH] fix(file): file.displayExtension should return lowercased extension T2874 --- spec-nylas/models/file-spec.coffee | 8 ++++++++ src/flux/models/file.coffee | 5 +++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/spec-nylas/models/file-spec.coffee b/spec-nylas/models/file-spec.coffee index 1cd98f445..e858b6527 100644 --- a/spec-nylas/models/file-spec.coffee +++ b/spec-nylas/models/file-spec.coffee @@ -36,6 +36,14 @@ describe "File", -> f = new File(filename: 'a', contentType: 'image/jpg') expect(f.displayExtension()).toBe('') + it "should ignore the case of the extension i nthe filename", -> + f = new File(filename: 'Hello world.JPG', contentType: 'image/jpg') + expect(f.displayExtension()).toBe('jpg') + f = new File(filename: 'Hello world.Jpg', contentType: 'image/jpg') + expect(f.displayExtension()).toBe('jpg') + f = new File(filename: 'Hello world.jpg', contentType: 'image/jpg') + expect(f.displayExtension()).toBe('jpg') + it "should return an extension based on the default filename otherwise", -> f = new File(filename: '', contentType: 'image/jpg') expect(f.displayExtension()).toBe('jpg') diff --git a/src/flux/models/file.coffee b/src/flux/models/file.coffee index 8da80ab0a..170ce05bf 100644 --- a/src/flux/models/file.coffee +++ b/src/flux/models/file.coffee @@ -69,11 +69,12 @@ class File extends Model # Public: Returns the file extension that should be used for this file. # Note that asking for the displayExtension is more accurate than trying to read - # the extension directly off the filename, and may be based on contentType. + # the extension directly off the filename. The returned extension may be based + # on contentType and is always lowercase. # # Returns the extension without the leading '.' (ex: 'png', 'pdf') # displayExtension: -> - path.extname(@displayName())[1..-1] + path.extname(@displayName().toLowerCase())[1..-1] module.exports = File