Skip to content

Commit

Permalink
sneaky edge case for comments in plaintext
Browse files Browse the repository at this point in the history
  • Loading branch information
aaronpk committed Jan 5, 2017
1 parent d45e16d commit f07755a
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/indieweb/comments.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
26 changes: 26 additions & 0 deletions tests/BasicTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 <script> tags from plaintext,
// so you could end up with <script><!-- foo --></script> leading to an HTML comment in the text.
// Also <div class="e-content">&lt;!-- Hello World --></div> will result in what looks like HTML comment in the value.
$result = IndieWeb\comments\parse($this->buildHEntry(array(
'name' => "post name",
'content' => [
'html' => "<p><!-- comment --></p>",
'value' => "<!-- comment -->"
]
)), false, 500);
$this->assertEquals('mention', $result['type']);
$this->assertEquals('post name', $result['name']);
}

/***************************************************************************
* Other post types
*/
Expand Down

0 comments on commit f07755a

Please sign in to comment.