From 673fcd7927a31ad39ebe6208731e351f2574d1e3 Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Fri, 28 Aug 2020 13:10:29 +0000 Subject: [PATCH] Comments: Check if reply heading text node exists before accessing its property in `comment-reply.js`. Follow-up to [47506], [48876]. Props johannadevos, mailnew2ster. Fixes #38009. git-svn-id: https://develop.svn.wordpress.org/trunk@48904 602fd350-edb4-49c9-b593-d223f7449a82 --- src/js/_enqueues/lib/comment-reply.js | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/js/_enqueues/lib/comment-reply.js b/src/js/_enqueues/lib/comment-reply.js index d86403bbeb..698e894304 100644 --- a/src/js/_enqueues/lib/comment-reply.js +++ b/src/js/_enqueues/lib/comment-reply.js @@ -175,11 +175,14 @@ window.addComment = ( function( window ) { var headingText = temporaryElement.textContent; temporaryElement.parentNode.replaceChild( respondElement, temporaryElement ); cancelLink.style.display = 'none'; - var replyHeadingElement = getElementById( config.commentReplyTitleId ); + + var replyHeadingElement = getElementById( config.commentReplyTitleId ); var replyHeadingTextNode = replyHeadingElement && replyHeadingElement.firstChild; + if ( replyHeadingTextNode && replyHeadingTextNode.nodeType === Node.TEXT_NODE && headingText ) { replyHeadingTextNode.textContent = headingText; } + event.preventDefault(); } @@ -314,7 +317,7 @@ window.addComment = ( function( window ) { var postIdField = getElementById( config.postIdFieldId ); var element, cssHidden, style; - var replyHeading = getElementById( config.commentReplyTitleId ); + var replyHeading = getElementById( config.commentReplyTitleId ); var replyHeadingTextNode = replyHeading && replyHeading.firstChild; if ( ! addBelowElement || ! respondElement || ! parentIdField ) { @@ -337,9 +340,11 @@ window.addComment = ( function( window ) { cancelElement.style.display = ''; addBelowElement.parentNode.insertBefore( respondElement, addBelowElement.nextSibling ); - if ( replyHeadingTextNode.nodeType === Node.TEXT_NODE ) { + + if ( replyHeadingTextNode && replyHeadingTextNode.nodeType === Node.TEXT_NODE ) { replyHeadingTextNode.textContent = replyTo; } + /* * This is for backward compatibility with third party commenting systems * hooking into the event using older techniques.