From 2ad0bab9764a94a8cb53d21428ec9709253cb5d1 Mon Sep 17 00:00:00 2001 From: Henry Oswald Date: Tue, 2 Aug 2016 15:28:53 +0100 Subject: [PATCH] =?UTF-8?q?use=20underscore.each=20so=20it=20doesn?= =?UTF-8?q?=E2=80=99t=20blow=20up=20on=20non=20array.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Features/References/ReferencesHandler.coffee | 14 +++++++------- .../References/ReferencesHandlerTests.coffee | 5 +++++ 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/services/web/app/coffee/Features/References/ReferencesHandler.coffee b/services/web/app/coffee/Features/References/ReferencesHandler.coffee index fa38ddedf6..3ceeab93f8 100644 --- a/services/web/app/coffee/Features/References/ReferencesHandler.coffee +++ b/services/web/app/coffee/Features/References/ReferencesHandler.coffee @@ -4,7 +4,7 @@ settings = require("settings-sharelatex") ProjectGetter = require "../Project/ProjectGetter" UserGetter = require "../User/UserGetter" DocumentUpdaterHandler = require('../DocumentUpdater/DocumentUpdaterHandler') -U = require('underscore') +_ = require('underscore') Async = require('async') oneMinInMs = 60 * 1000 @@ -22,24 +22,24 @@ module.exports = ReferencesHandler = _findBibFileIds: (project) -> ids = [] _process = (folder) -> - (folder.fileRefs or []).forEach (file) -> + _.each (folder.fileRefs or []), (file) -> if file?.name?.match(/^.*\.bib$/) ids.push(file._id) - (folder.folders or []).forEach (folder) -> + _.each (folder.folders or []), (folder) -> _process(folder) - (project.rootFolder or []).forEach (rootFolder) -> + _.each (project.rootFolder or []), (rootFolder) -> _process(rootFolder) return ids _findBibDocIds: (project) -> ids = [] _process = (folder) -> - (folder.docs or []).forEach (doc) -> + _.each (folder.docs or []), (doc) -> if doc?.name?.match(/^.*\.bib$/) ids.push(doc._id) - (folder.folders or []).forEach (folder) -> + _.each (folder.folders or []), (folder) -> _process(folder) - (project.rootFolder or []).forEach (rootFolder) -> + _.each (project.rootFolder or []), (rootFolder) -> _process(rootFolder) return ids diff --git a/services/web/test/UnitTests/coffee/References/ReferencesHandlerTests.coffee b/services/web/test/UnitTests/coffee/References/ReferencesHandlerTests.coffee index c46e71a542..c69cb3ee0a 100644 --- a/services/web/test/UnitTests/coffee/References/ReferencesHandlerTests.coffee +++ b/services/web/test/UnitTests/coffee/References/ReferencesHandlerTests.coffee @@ -322,6 +322,11 @@ describe 'ReferencesHandler', -> result = @handler._findBibDocIds(@fakeProject) expect(result).to.deep.equal @expectedIds + it 'should not error with a non array of folders from dirty data', -> + @fakeProject.rootFolder[0].folders[0].folders = {} + result = @handler._findBibDocIds(@fakeProject) + expect(result).to.deep.equal @expectedIds + describe '_findBibFileIds', -> beforeEach ->