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 previous and next helpers #5180

Merged
merged 2 commits into from
Apr 22, 2015
Merged

Fix previous and next helpers #5180

merged 2 commits into from
Apr 22, 2015

Conversation

ErisDS
Copy link
Member

@ErisDS ErisDS commented Apr 22, 2015

fixes #5177

This bug is caused by an interesting collection of oddnesses. All of the tests for the next/previous API calls and for the helper are passing, and that's not strictly incorrect. However the call the next/prev helper makes to the API includes all of the options from the helper, including one called name.

In #5159, I changed the API/models to always pass options through to toJSON. However, those options are only filtered in the model layer, not the API layer, so in cases where the API calls toJSON (E.g. the posts.read call used in the next/prev helpers) the options passed in are unsanitized. This was a massive oversight on my part.

Deep inside of toJSON, there is some code to handle nested relations. This code makes use of a name option that gets passed recursively to toJSON in order to create nested keys.

As a result of the combination of these things: options from the helper getting passed through to the API, not being filtered, and then being used in toJSON the name property from the helper was incorrectly being used as the base for the key in toJSON, meaning that the next and previous posts were being casually thrown away before the API returned. Epic.

This PR contains two separate fixes for the two separate issues. The first one adds filtering to toJSON so that only allowed options are passed through. It also renames name to baseKey which is more specific and less likely to clash with other things. The second one changes the prev/next helper to not pass through the options from the helper to the API.

Normally I'd do these as 2 separate PRs, but in the interest of expediency (cough travis cough I've combined them into one).

fixes TryGhost#5177

- we now pass API/model options directly to toJSON, which is unsafe as these options haven't always been filtered before they are passed.
- this fix adds a filter so that toJSON only uses the options it needs
- additionally, rename the 'name' option to something more specific to prevent clashes
fixes TryGhost#5177

- this combined with a change passing options through to toJSON results in a really flukey bug with next/prev
  where the name option from the helper clashes with a name option inside of toJSON
sebgie added a commit that referenced this pull request Apr 22, 2015
Fix previous and next helpers
@sebgie sebgie merged commit 599af34 into TryGhost:master Apr 22, 2015
@ErisDS ErisDS deleted the issue-5177 branch June 22, 2015 18:21
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.

prev / next not appearing after updating to 0.6.1
2 participants