Skip to content

Commit

Permalink
Add another test and sanitize the result of rrulestr
Browse files Browse the repository at this point in the history
Parameters passed into parseRRule() as a string, that shouldn't be sanitized, should not be sanitized. So I added a test for that.
  • Loading branch information
joelzanden committed Apr 1, 2020
1 parent 64438fb commit 3f3accf
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 9 deletions.
24 changes: 20 additions & 4 deletions packages/__tests__/src/datelib/rrule.js
Expand Up @@ -64,7 +64,7 @@ describe('rrule plugin', function() {
expect(events[4].start).toEqualDate('2018-10-02T13:00:00Z')
})

it('can expand monthly recurrence', function() {
it('can expand monthly recurrence when given an rrule object', function() {
initCalendar({
defaultView: 'dayGridMonth',
now: '2018-12-25T12:00:00',
Expand All @@ -83,6 +83,21 @@ describe('rrule plugin', function() {
expect(events[0].start).toEqualDate('2018-12-13')
})

// https://github.com/fullcalendar/fullcalendar/issues/4955
it('can expand monthly recurrence when given an rrule string', function() {
initCalendar({
defaultView: 'dayGridMonth',
now: '2018-12-25T12:00:00',
events: [ {
rrule: 'DTSTART:20181101\nRRULE:FREQ=MONTHLY;COUNT=13;BYMONTHDAY=13'
} ]
})

let events = currentCalendar.getEvents()
expect(events.length).toBe(1)
expect(events[0].start).toEqualDate('2018-12-13')
})

it('expands events until a date', function() {
initCalendar({
events: [
Expand Down Expand Up @@ -202,7 +217,7 @@ describe('rrule plugin', function() {
expect(events[0].allDay).toBe(false)
})

it('can generate local dates when rrule is defined in object form', function() {
it('can generate local dates when given an rrule object', function() {
initCalendar({
timeZone: 'local',
events: [
Expand All @@ -220,8 +235,9 @@ describe('rrule plugin', function() {
expect(events[0].end).toBe(null)
expect(events[0].allDay).toBe(false)
})

it('can generate local dates when rrule is defined as icalendar string', function() {

// https://github.com/fullcalendar/fullcalendar/issues/4955
it('can generate local dates when given an rrule string', function() {
const localDateToUTCIsoString = parseLocalDate('2018-09-04T05:00:00').toISOString()
const modified = localDateToUTCIsoString.replace('.000', '').replace(/[\-\:]/g, '')
initCalendar({
Expand Down
37 changes: 32 additions & 5 deletions packages/rrule/src/main.ts
Expand Up @@ -58,11 +58,36 @@ export default createPlugin({
function parseRRule(input, dateEnv: DateEnv) {
let allDayGuess = null
let rrule

if (typeof input === 'string') {
rrule = rrulestr(input)
let rruleTemp = rrulestr(input)

if (rruleTemp.origOptions.dtstart != null) {
rruleTemp.origOptions.dtstart = dateEnv.createMarker(rruleTemp.origOptions.dtstart)
}

if (rruleTemp.origOptions.until != null) {
rruleTemp.origOptions.until = dateEnv.createMarker(rruleTemp.origOptions.until)
}

if (rruleTemp.origOptions.freq != null) {
rruleTemp.origOptions.freq = convertConstant(rruleTemp.origOptions.freq)
}

} else if (typeof input === 'object' && input) { // non-null object
if (rruleTemp.origOptions.wkst != null) {
rruleTemp.origOptions.wkst = convertConstant(rruleTemp.origOptions.wkst)
}
else {
rruleTemp.origOptions.wkst = (dateEnv.weekDow - 1 + 7) % 7 // convert Sunday-first to Monday-first
}

if (rruleTemp.origOptions.byweekday != null) {
rruleTemp.origOptions.byweekday = convertConstants(rruleTemp.origOptions.byweekday) // the plural version
}

rrule = new RRule(rruleTemp.origOptions)
}
else if (typeof input === 'object' && input) { // non-null object
let refined = { ...input } // copy

if (typeof refined.dtstart === 'string') {
Expand All @@ -71,7 +96,8 @@ function parseRRule(input, dateEnv: DateEnv) {
if (dtstartMeta) {
refined.dtstart = dtstartMeta.marker
allDayGuess = dtstartMeta.isTimeUnspecified
} else {
}
else {
delete refined.dtstart
}
}
Expand All @@ -86,7 +112,8 @@ function parseRRule(input, dateEnv: DateEnv) {

if (refined.wkst != null) {
refined.wkst = convertConstant(refined.wkst)
} else {
}
else {
refined.wkst = (dateEnv.weekDow - 1 + 7) % 7 // convert Sunday-first to Monday-first
}

Expand Down

0 comments on commit 3f3accf

Please sign in to comment.