From c78b249c663147416ef1dcd752e91e63b9aa30e9 Mon Sep 17 00:00:00 2001 From: Oiva Eskola Date: Sat, 11 Sep 2021 17:24:24 +0300 Subject: [PATCH] Fix falsy values not being returned in post fields (#29011) 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` --- examples/blog-starter-typescript/lib/api.ts | 2 +- examples/blog-starter/lib/api.js | 2 +- examples/blog-with-comment/lib/getPost.js | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/examples/blog-starter-typescript/lib/api.ts b/examples/blog-starter-typescript/lib/api.ts index cf3be86f0b0f8..be2edfd854e78 100644 --- a/examples/blog-starter-typescript/lib/api.ts +++ b/examples/blog-starter-typescript/lib/api.ts @@ -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] } }) diff --git a/examples/blog-starter/lib/api.js b/examples/blog-starter/lib/api.js index 08da07eb78ab8..b9612a8ac5366 100644 --- a/examples/blog-starter/lib/api.js +++ b/examples/blog-starter/lib/api.js @@ -25,7 +25,7 @@ export function getPostBySlug(slug, fields = []) { items[field] = content } - if (data[field]) { + if (typeof data[field] !== 'undefined') { items[field] = data[field] } }) diff --git a/examples/blog-with-comment/lib/getPost.js b/examples/blog-with-comment/lib/getPost.js index 08da07eb78ab8..b9612a8ac5366 100644 --- a/examples/blog-with-comment/lib/getPost.js +++ b/examples/blog-with-comment/lib/getPost.js @@ -25,7 +25,7 @@ export function getPostBySlug(slug, fields = []) { items[field] = content } - if (data[field]) { + if (typeof data[field] !== 'undefined') { items[field] = data[field] } })