From b7e078e98d4ac2c17a2952f14f979792fd749f0c Mon Sep 17 00:00:00 2001 From: Zeke Sikelianos Date: Thu, 6 Oct 2016 14:37:13 -0700 Subject: [PATCH] sanitize MenuItem options --- lib/browser/api/menu-item.js | 5 +++++ spec/api-menu-spec.js | 6 ++++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/lib/browser/api/menu-item.js b/lib/browser/api/menu-item.js index 3f4892b59f5a..8103aaf2b7e9 100644 --- a/lib/browser/api/menu-item.js +++ b/lib/browser/api/menu-item.js @@ -7,6 +7,11 @@ let nextCommandId = 0 const MenuItem = function (options) { const {Menu} = require('electron') + // Clone and sanitize the provided options + options = Object.assign({}, options) + delete options.overrideProperty + delete options.overrideReadOnlyProperty + Object.assign(this, options) if (this.submenu != null && this.submenu.constructor !== Menu) { diff --git a/spec/api-menu-spec.js b/spec/api-menu-spec.js index 7cd023b95dba..56c43ad47800 100644 --- a/spec/api-menu-spec.js +++ b/spec/api-menu-spec.js @@ -431,7 +431,7 @@ describe('menu module', function () { }) }) -describe.only('MenuItem with custom properties in constructor', function () { +describe('MenuItem with custom properties in constructor', function () { it('preserves the custom properties', function () { var template = [{ label: 'menu 1', @@ -442,11 +442,13 @@ describe.only('MenuItem with custom properties in constructor', function () { var menu = Menu.buildFromTemplate(template) menu.items[0].submenu.append(new MenuItem({ label: 'item 1', - customProp: 'bar' + customProp: 'bar', + overrideProperty: 'oops not allowed' })) assert.equal(menu.items[0].customProp, 'foo') assert.equal(menu.items[0].submenu.items[0].label, 'item 1') assert.equal(menu.items[0].submenu.items[0].customProp, 'bar') + assert.notEqual(typeof menu.items[0].submenu.items[0].overrideProperty, 'string') }) })