Fix "Empty string supplied as input" bug #647
Conversation
Fix `PHP Warning: DOMDocument::loadHTML(): Empty string supplied as input`, by verifying the content and making sure if it is empty, do not `transformString`.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
get_the_content calls has few filters, and probably calling twice should be avoided.
Thanks for your PRs @abdusfauzi
class-instant-articles-post.php
Outdated
@@ -690,7 +690,9 @@ public function to_instant_article() { | |||
Video::setDefaultCommentEnabled( $settings_publishing[ 'comments_on_media' ] ); | |||
} | |||
|
|||
$transformer->transformString( $this->instant_article, $this->get_the_content(), get_option( 'blog_charset' ) ); | |||
if ( '' != $this->get_the_content() ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this happening to you?
I'd change this, so we call only once the get_the_content()
method here.
Can you do it like this:
$the_content = $this->get_the_content();
if ( '' != $the_content ) {
$transformer->transformString...
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cool. No problem 👌🏻
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@everton-rosario Rewrite the fix to reduce the get_the_content()
call only once.
class-instant-articles-post.php
Outdated
@@ -690,7 +690,9 @@ public function to_instant_article() { | |||
Video::setDefaultCommentEnabled( $settings_publishing[ 'comments_on_media' ] ); | |||
} | |||
|
|||
$transformer->transformString( $this->instant_article, $this->get_the_content(), get_option( 'blog_charset' ) ); | |||
if ( '' != $this->get_the_content() ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cool. No problem 👌🏻
class-instant-articles-post.php
Outdated
$transformer->transformString( $this->instant_article, $this->get_the_content(), get_option( 'blog_charset' ) ); | ||
|
||
$the_content = $this->get_the_content(); | ||
if ( '' != $the_content ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you please use the Type::isTextEmpty() method for this? Ty
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@vkama i'm sorry, i wish i understand how to use the suggested Type:isTextEmpty()
😰 Would you mind show me sample?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use Facebook\InstantArticles\Validators\Type;
if (!Type::isTextEmpty($the_content)) { ... }
class-instant-articles-post.php
Outdated
@@ -691,7 +693,7 @@ public function to_instant_article() { | |||
} | |||
|
|||
$the_content = $this->get_the_content(); | |||
if ( '' != $the_content ) { | |||
if (!Type::isTextEmpty($the_content)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good job ty
This PR:
Fixes #
Fix
PHP Warning: DOMDocument::loadHTML(): Empty string supplied as input
, by verifying the content and making sure if it is empty, do nottransformString
.Automattic/facebook-instant-articles-wp#628