From 1688689dc8072bd4731266838ade44209839a654 Mon Sep 17 00:00:00 2001 From: Sergey Kruk Date: Wed, 22 Jul 2015 00:25:44 +0300 Subject: [PATCH] feat(preprocessor): Capital letters in binary files extenstions Use lower case file extension to detect if it is binary Closes #1508 --- lib/preprocessor.js | 2 +- test/unit/preprocessor.spec.coffee | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/lib/preprocessor.js b/lib/preprocessor.js index bfeae6dbb..cb5e424a1 100644 --- a/lib/preprocessor.js +++ b/lib/preprocessor.js @@ -47,7 +47,7 @@ var createPreprocessor = function (config, basePath, injector) { return function preprocess (file, done) { patterns = Object.keys(config) - var thisFileIsBinary = isBinary[path.extname(file.originalPath)] + var thisFileIsBinary = isBinary[path.extname(file.originalPath).toLowerCase()] var preprocessors = [] var nextPreprocessor = function (error, content) { diff --git a/test/unit/preprocessor.spec.coffee b/test/unit/preprocessor.spec.coffee index 8cda0d3aa..d5d96c310 100644 --- a/test/unit/preprocessor.spec.coffee +++ b/test/unit/preprocessor.spec.coffee @@ -14,6 +14,7 @@ describe 'preprocessor', -> 'b.js': mocks.fs.file 0, 'content' 'a.txt': mocks.fs.file 0, 'some-text' 'photo.png': mocks.fs.file 0, 'binary' + 'CAM_PHOTO.JPG': mocks.fs.file 0, 'binary' mocks_ = 'graceful-fs': mockFs @@ -195,3 +196,21 @@ describe 'preprocessor', -> expect(fakePreprocessor).not.to.have.been.called expect(file.content).to.be.an.instanceof Buffer done() + + + it 'should not preprocess binary files with capital letters in extension', (done) -> + fakePreprocessor = sinon.spy (content, file, done) -> + done null, content + + injector = new di.Injector [{ + 'preprocessor:fake': ['factory', -> fakePreprocessor] + }] + + pp = m.createPreprocessor {'**/*': ['fake']}, null, injector + + file = {originalPath: '/some/CAM_PHOTO.JPG', path: 'path'} + + pp file, (err) -> + expect(fakePreprocessor).not.to.have.been.called + expect(file.content).to.be.an.instanceof Buffer + done()