Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix condition that use potential undefined variable and crash the application #1480

Merged
merged 1 commit into from
Jul 10, 2018

Conversation

Seao
Copy link
Contributor

@Seao Seao commented Jul 10, 2018

Bug

It's possible to define pieces selected through the property by in custom pieces widget.
However set by to ['all'] crashs the application, which try to read a property of an undefined value in an if condition.

How to reproduce

Create a custom pieces widget extending apostrophe-pieces-widgets with the following by restriction:

module.exports = {
  extend: 'apostrophe-pieces-widgets',
  by: ['all'],
  ...
}

Try to run the application, which will crash with the following error

TypeError: Cannot read property 'relationship' of undefined
    at Object.self.pushPieceForWidget (/Users/seao/Travail/Stage/Michelin/bicycle/node_modules/apostrophe/lib/modules/apostrophe-pieces-widgets/index.js:297:24)
    at ...

Fix

Change

if (self.joinById.relationship && (widget.by === 'id'))

to

if (self.joinById && self.joinById.relationship && (widget.by === 'id'))

as self.joinById can be undefined

@boutell boutell merged commit 0e8c703 into apostrophecms:master Jul 10, 2018
@boutell
Copy link
Member

boutell commented Jul 10, 2018

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants