Skip to content

Commit f07755a

Browse files
committed
sneaky edge case for comments in plaintext
1 parent d45e16d commit f07755a

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

src/indieweb/comments.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,9 @@ function parse($mf, $refURL=false, $maxTextLength=150, $maxLines=2) {
257257
if($nameSanitized != $contentSanitized and $nameSanitized !== '') {
258258
// If the name is the beginning of the content, we don't care
259259
// Same if the content is the beginning of the name (like with really long notes)
260-
if(!(strpos($contentSanitized, $nameSanitized) === 0) && !(strpos($nameSanitized, $contentSanitized) === 0)) {
260+
if($contentSanitized === ''
261+
|| (!(strpos($contentSanitized, $nameSanitized) === 0) && !(strpos($nameSanitized, $contentSanitized) === 0))
262+
) {
261263
// The name was determined to be different from the content, so return it
262264
$name = $properties['name'][0]; //truncate($properties['name'][0], $maxTextLength, $maxLines);
263265
}

tests/BasicTest.php

+26
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,32 @@ public function testBnvk() {
281281
\t\tMar 30, 2014", $result['text']);
282282
}
283283

284+
public function testMentionNoNameWithContent() {
285+
$result = IndieWeb\comments\parse($this->buildHEntry(array(
286+
'name' => '',
287+
'content' => 'post name'
288+
)), false, 90);
289+
$this->assertEquals('mention', $result['type']);
290+
$this->assertEquals('', $result['name']);
291+
$this->assertEquals('post name', $result['text']);
292+
}
293+
294+
public function testMentionCommentedContentWithName() {
295+
// It's possible for the plaintext to end up with an HTML comment for various reasons.
296+
// Version 0.2.* of php-mf2 failed to remove the contents of <script> tags from plaintext,
297+
// so you could end up with <script><!-- foo --></script> leading to an HTML comment in the text.
298+
// Also <div class="e-content">&lt;!-- Hello World --></div> will result in what looks like HTML comment in the value.
299+
$result = IndieWeb\comments\parse($this->buildHEntry(array(
300+
'name' => "post name",
301+
'content' => [
302+
'html' => "<p><!-- comment --></p>",
303+
'value' => "<!-- comment -->"
304+
]
305+
)), false, 500);
306+
$this->assertEquals('mention', $result['type']);
307+
$this->assertEquals('post name', $result['name']);
308+
}
309+
284310
/***************************************************************************
285311
* Other post types
286312
*/

0 commit comments

Comments
 (0)