t('[220783] HTML markup is counted in for the length of trimmed posts'), 'desc' => t('HTML markup should not be counted as "characters" when determining where to trim the post. Currently this causes a particular problem with feeds which often embed a lot of tags in their content, and for which reliable automatic teaser generation is a must. Attached patch uses a regex to allow the node_teaser() function to work out where in $body corresponds to 600 characters (or whatever the value of $size is) of actual content.'), 'group' => t('Drupal 7 Tests'), ); } function testIssue() { $teaser_size = 100; $tags_count = 10; $tag_size = 5; // Create some random tags $html_tags = array(); $html_tags[] = '<'.$this->randomName($tag_size, '').'>'; // open tag $html_tags[] = 'randomName($tag_size, '').'>'; // close tag $html_tags[] = ''; // comment $html_tags[] = '<'.$this->randomName($tag_size, '').'/>'; // only tag // Create sample body with tags. // Tags must be skipped from expected character count $real_length = 0; $body = ''; $expected_teaser = ''; $teaser_flag = true; for ($i = 0; $i < $tags_count * 2; $i++) { $html_tag = $html_tags[$i%count($html_tags)]; $chunk_size = ($teaser_size * 2 - $tags_count * $tag_size * 2) / count ($html_tags); $chunk = $this->randomName(mt_rand(0, $chunk_size), ''); $real_length += drupal_strlen($chunk); if ($real_length <= $teaser_size) { $expected_teaser .= $chunk . $html_tag; } else if ($teaser_flag) { $expected_teaser .= drupal_substr($chunk, 0, $teaser_size - $real_length); $teaser_flag = false; } $body .= $chunk . $html_tag; } $teaser = node_teaser($body, null, $teaser_size); $this->assertIdentical($teaser, $expected_teaser); } }