Breaks JSON/REST-API Output
-
WP Fastest Cache adds String “<!– html is corrupted –>” to end of JSON/REST-API output of WordPress which leads to invalid JSON.
Examples:
- hXXp://www.wpfastestcache.com/wp-json/wp/v2/posts
- hXXp://www.wpfastestcache.com/wp-json/wp/v2/users
Please fix soon, thanks.
-
This topic was modified 9 years, 3 months ago by
ov3rfly.
-
No need to detect json pages or similar. Start thinking the other way round, only add HTML-comments if you know it is HTML-data. Problem solved.
WP Fastest Cache adds String “<!– html is corrupted –>” to end of JSON/REST-API output of WordPress which leads to invalid JSON.
Examples:
hXXp://www.wpfastestcache.com/wp-json/wp/v2/posts
hXXp://www.wpfastestcache.com/wp-json/wp/v2/users
Please fix soon, thanks.I have fixed it few minutes ago but I did not release a new version. You should download the following version.
Testcases on your server still have
<!– html is corrupted –>added.Downloaded .zip says 0.8.6.6 in header and still has this code in
../inc/cache.phpwhich obviously will print the comment to anything which does not have anhtmlandbodytag.}else if($this->checkHtml($buffer)){ return $buffer."<!-- html is corrupted -->"; }elseLet me know if a real fix as described above is ready, take your time, as described this can not be solved by comparing some strings in URLs.
Thanks for the quick feedback.
I have added the following code.
if(preg_match(“/^\/wp-json/”, $_SERVER[“REQUEST_URI”])){
return true;
}As explained, that’s not a real fix, just a quick hack workaround which does not cover all kind of other endpoints which deliver JSON or similar.
Start thinking the other way round, only add HTML-comments if you know it is HTML-data. Problem solved.
You are %100 right but I cannot detect that the page is html or json. You should get and use the temp solution.
As explained, if you cannot detect html or json, do not add HTML-comments.
Minimum fix:
}else if($this->checkHtml($buffer)){ return $buffer; }elseMinimum fix with debug info:
}else if($this->checkHtml($buffer)){ if ( WP_DEBUG ) error_log( 'WPFC: <!– html is corrupted –>' ); return $buffer; }elseok, you are right.
Is this fixed yet?
Hi @songofhannah, The urls which start with /wp-json/ are not cached with the following version.
The URL above looks to be the WP latest version. So all I need to do it update, right?
The code in 0.8.6.7 still adds HTML-comments to any non-HTML data.
Please add a real fix as described above.
Excluding certain URLs from cache just hides the problem and actually also defeats the purpose of a cache plugin.
The URL above looks to be the WP latest version. So all I need to do it update, right?
yes.
The code in 0.8.6.7 still adds HTML-comments to any non-HTML data.
Please add a real fix as described above.
Excluding certain URLs from cache just hides the problem and actually also defeats the purpose of a cache plugin.
Please contact me via email: http://www.wpfastestcache.com/contact-us/
The code in 0.8.6.7 still adds HTML-comments to any non-HTML data.
This bug still affects any custom WordPress endpoints.
How to reproduce? Create an own endpoint.
Find a full example as plugin here, link to github gist at end of article.
With above plugin, add a “GIFs” item with a tag
sdfOpen link to endpoint in browser:
http://example.com/gifs/sdf/Get corrupted JSON:
[{"link":"http:\/\/example.com\/wp-content\/uploads\/2017\/01\/example.jpg","title":"test"}]<!-- html is corrupted -->Another Link with non-existing GIF-tag:
http://example.com/gifs/yxcvb/[]<!-- html is corrupted -->No need to contact you via email, there is enough information above already.
The real fix: Only add HTML-comments if you know it is HTML-data. If you can’t detect page format, do not add anything at all. Problem solved.
@ov3rfly, please contact me via email and I will fix it.
The topic ‘Breaks JSON/REST-API Output’ is closed to new replies.