From 93069fad7572a2cc5aa363ea86c3d8e6deaf3d58 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Tue, 7 Jul 2015 12:20:01 -0700 Subject: [PATCH] Add stricter object checking --- spec/notification-spec.coffee | 3 +++ src/notification.coffee | 3 ++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/spec/notification-spec.coffee b/spec/notification-spec.coffee index 9c6edbfd6..ef07ff61c 100644 --- a/spec/notification-spec.coffee +++ b/spec/notification-spec.coffee @@ -8,16 +8,19 @@ describe "Notification", -> expect(-> new Notification('error', 3)).toThrow() expect(-> new Notification('error', {})).toThrow() expect(-> new Notification('error', false)).toThrow() + expect(-> new Notification('error', [])).toThrow() it "throws an error when created with non-object options", -> expect(-> new Notification('error', 'message', 'foo')).toThrow() expect(-> new Notification('error', 'message', 3)).toThrow() expect(-> new Notification('error', 'message', false)).toThrow() + expect(-> new Notification('error', 'message', [])).toThrow() it "throws an error when created with a non-string detail", -> expect(-> new Notification('error', 'message', detail: 3)).toThrow() expect(-> new Notification('error', 'message', detail: false)).toThrow() expect(-> new Notification('error', 'message', detail: {})).toThrow() + expect(-> new Notification('error', 'message', detail: [])).toThrow() describe "::getTimestamp()", -> it "returns a Date object", -> diff --git a/src/notification.coffee b/src/notification.coffee index 5aea47fa7..fb5466526 100644 --- a/src/notification.coffee +++ b/src/notification.coffee @@ -1,4 +1,5 @@ {Emitter} = require 'event-kit' +_ = require 'underscore-plus' # Public: A notification to the user containing a message and type. module.exports = @@ -15,7 +16,7 @@ class Notification if typeof @message isnt 'string' throw new Error("Notification must be created with string message: #{@message}") - if typeof @options isnt 'object' + unless _.isObject(@options) and not _.isArray(@options) throw new Error("Notification must be created with an options object: #{@options}") if @options?.detail? and typeof @options.details isnt 'string'