Skip to content

Commit

Permalink
fix infinite recursion when custom view type is itself. fixes #4198
Browse files Browse the repository at this point in the history
  • Loading branch information
arshaw committed Aug 6, 2019
1 parent 1771b0e commit 262e551
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
next
----

- fix infinite recursion when custom view type is itself (#4198)
- respect firstDay setting when weekNumberCalculation set to ISO (#4734)
- fix typo in Danish (#4708)
- adjust typescript def for setExtendedProp (#4679)
Expand Down
20 changes: 20 additions & 0 deletions packages/__tests__/src/legacy/custom-view-duration.js
Original file line number Diff line number Diff line change
Expand Up @@ -375,4 +375,24 @@ describe('custom view', function() {
expect($('.fc-crazy-button')).toHaveText('crazy')
})
})

it('throws an error when type is self', function() {
let error = null

try {
initCalendar({
defaultView: 'month',
views: {
month: {
type: 'month'
}
}
})
} catch (_error) {
error = _error
}

expect(error).toBeTruthy()
expect(error.message).toBe('Can\'t have a custom view type that references itself')
})
})
11 changes: 10 additions & 1 deletion packages/core/src/structs/view-def.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,16 @@ function buildViewDef(viewType: string, hash: ViewDefHash, defaultConfigs: ViewC
findViewNameBySubclass(theClass, defaultConfigs)
}

let superDef = superType ? ensureViewDef(superType, hash, defaultConfigs, overrideConfigs) : null
let superDef: ViewDef | null = null

if (superType) {

if (superType === viewType) {
throw new Error('Can\'t have a custom view type that references itself')
}

superDef = ensureViewDef(superType, hash, defaultConfigs, overrideConfigs)
}

if (!theClass && superDef) {
theClass = superDef.class
Expand Down

0 comments on commit 262e551

Please sign in to comment.