From f07755af71e0b310b8b68b560561fe6f11192392 Mon Sep 17 00:00:00 2001 From: Aaron Parecki Date: Thu, 5 Jan 2017 10:21:22 -0800 Subject: [PATCH] sneaky edge case for comments in plaintext --- src/indieweb/comments.php | 4 +++- tests/BasicTest.php | 26 ++++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/src/indieweb/comments.php b/src/indieweb/comments.php index 1f3e544..5596079 100644 --- a/src/indieweb/comments.php +++ b/src/indieweb/comments.php @@ -257,7 +257,9 @@ function parse($mf, $refURL=false, $maxTextLength=150, $maxLines=2) { if($nameSanitized != $contentSanitized and $nameSanitized !== '') { // If the name is the beginning of the content, we don't care // Same if the content is the beginning of the name (like with really long notes) - if(!(strpos($contentSanitized, $nameSanitized) === 0) && !(strpos($nameSanitized, $contentSanitized) === 0)) { + if($contentSanitized === '' + || (!(strpos($contentSanitized, $nameSanitized) === 0) && !(strpos($nameSanitized, $contentSanitized) === 0)) + ) { // The name was determined to be different from the content, so return it $name = $properties['name'][0]; //truncate($properties['name'][0], $maxTextLength, $maxLines); } diff --git a/tests/BasicTest.php b/tests/BasicTest.php index cc8e1f4..500267c 100644 --- a/tests/BasicTest.php +++ b/tests/BasicTest.php @@ -281,6 +281,32 @@ public function testBnvk() { \t\tMar 30, 2014", $result['text']); } + public function testMentionNoNameWithContent() { + $result = IndieWeb\comments\parse($this->buildHEntry(array( + 'name' => '', + 'content' => 'post name' + )), false, 90); + $this->assertEquals('mention', $result['type']); + $this->assertEquals('', $result['name']); + $this->assertEquals('post name', $result['text']); + } + + public function testMentionCommentedContentWithName() { + // It's possible for the plaintext to end up with an HTML comment for various reasons. + // Version 0.2.* of php-mf2 failed to remove the contents of leading to an HTML comment in the text. + // Also
<!-- Hello World -->
will result in what looks like HTML comment in the value. + $result = IndieWeb\comments\parse($this->buildHEntry(array( + 'name' => "post name", + 'content' => [ + 'html' => "

", + 'value' => "" + ] + )), false, 500); + $this->assertEquals('mention', $result['type']); + $this->assertEquals('post name', $result['name']); + } + /*************************************************************************** * Other post types */