From 0589a38dd0e99a190cd714d754ba8386ce042667 Mon Sep 17 00:00:00 2001 From: nolledgeable Date: Mon, 18 Oct 2021 09:26:54 +0200 Subject: [PATCH] add string typecheck before checking length prop on authorname --- .../src/facebook/FacebookSiteAndAuthorNames.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/packages/social-metadata-previews/src/facebook/FacebookSiteAndAuthorNames.js b/packages/social-metadata-previews/src/facebook/FacebookSiteAndAuthorNames.js index ed7d6d646ec..9f1bd6a7a5c 100644 --- a/packages/social-metadata-previews/src/facebook/FacebookSiteAndAuthorNames.js +++ b/packages/social-metadata-previews/src/facebook/FacebookSiteAndAuthorNames.js @@ -3,6 +3,7 @@ import React, { Fragment } from "react"; import styled from "styled-components"; import PropTypes from "prop-types"; import { __, sprintf } from "@wordpress/i18n"; +import { isString } from "lodash"; /* Internal dependencies */ import FacebookAuthorName from "./FacebookAuthorName"; @@ -59,11 +60,13 @@ function renderFacebookAuthorName( authorName ) { * Renders a FacebookSiteAndAuthorNames component. * * @param {object} props The props. + * @param {string} props.authorName The author's name. + * @param {string} props.siteUrl The site url. * * @returns {React.Element} The rendered element. */ const FacebookSiteAndAuthorNames = ( props ) => { - const hasAuthorName = props.authorName.length > 0; + const hasAuthorName = isString( props.authorName ) && props.authorName.length > 0; const screenReaderText = hasAuthorName /* Translators: 1: site name, 2: post author name */ ? sprintf( __( "%1$s by %2$s", "yoast-components" ), props.siteUrl, props.authorName )