diff --git a/lib/rrule.js b/lib/rrule.js index b349f37e..c978e1d8 100644 --- a/lib/rrule.js +++ b/lib/rrule.js @@ -446,13 +446,16 @@ // used by toString() this.origOptions = {} + this.options = {} + var invalid = [] var keys = Object.keys(options) var defaultKeys = Object.keys(RRule.DEFAULT_OPTIONS) - // Shallow copy for origOptions and check for invalid + // Shallow copy for options and origOptions and check for invalid keys.forEach(function (key) { this.origOptions[key] = options[key] + this.options[key] = options[key] if (!contains(defaultKeys, key)) invalid.push(key) }, this) @@ -464,10 +467,10 @@ // Merge in default options defaultKeys.forEach(function (key) { - if (!contains(keys, key)) options[key] = RRule.DEFAULT_OPTIONS[key] - }) + if (!contains(keys, key)) this.options[key] = RRule.DEFAULT_OPTIONS[key] + }, this) - var opts = this.options = options + var opts = this.options if (opts.byeaster !== null) opts.freq = RRule.YEARLY if (!opts.dtstart) opts.dtstart = new Date(new Date().setMilliseconds(0)) diff --git a/test/rrule.js b/test/rrule.js index e6d1675a..7ca4e794 100644 --- a/test/rrule.js +++ b/test/rrule.js @@ -88,6 +88,24 @@ describe('RRule', function () { }) }) + it('does not mutate the passed-in options object', function () { + var options = { + freq: RRule.MONTHLY, + dtstart: new Date(2013, 0, 1), + count: 3, + bymonthday: [28] + } + var rule = new RRule(options) + + assert.deepEqual(options, { + freq: RRule.MONTHLY, + dtstart: new Date(2013, 0, 1), + count: 3, + bymonthday: [28] + }) + assert.deepEqual(rule.origOptions, options) + }) + testRecurring('missing Feb 28 https://github.com/jakubroztocil/rrule/issues/21', new RRule({ freq: RRule.MONTHLY,