Skip to content

Commit

Permalink
Fix falsy values not being returned in post fields (vercel#29011)
Browse files Browse the repository at this point in the history
I imported a bunch of old markdown posts to the blog-starter example but some of the post metadata was not returned by the API in the example code.

For example, having `published: false` in post metadata was not returned in the item fields.

The problem was in check:
```
if (data[field]) {
  items[field] = data[field]
}
```
This rejects all falsy values in addition to fields that are not set. Checking only for `undefined` should fix this issue.

I didn't find existing integration tests for the blog example nor an issue describing this problem.



## Bug

- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Errors have helpful link attached, see `contributing.md`
  • Loading branch information
oiva authored Sep 11, 2021
1 parent 0d0f34b commit c78b249
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion examples/blog-starter-typescript/lib/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export function getPostBySlug(slug: string, fields: string[] = []) {
items[field] = content
}

if (data[field]) {
if (typeof data[field] !== 'undefined') {
items[field] = data[field]
}
})
Expand Down
2 changes: 1 addition & 1 deletion examples/blog-starter/lib/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export function getPostBySlug(slug, fields = []) {
items[field] = content
}

if (data[field]) {
if (typeof data[field] !== 'undefined') {
items[field] = data[field]
}
})
Expand Down
2 changes: 1 addition & 1 deletion examples/blog-with-comment/lib/getPost.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export function getPostBySlug(slug, fields = []) {
items[field] = content
}

if (data[field]) {
if (typeof data[field] !== 'undefined') {
items[field] = data[field]
}
})
Expand Down

0 comments on commit c78b249

Please sign in to comment.