3

In Drupal6, I have a WYSIWYG input filter with the HTML Corrector filter enabled. When the body is automatically truncated for use in the teaser, sometimes the break occurs in the middle of an attribute value in an HTML tag (e.g. in the middle of the url in an anchor's href), resulting in an unclosed quotation mark. The HTML corrector appears to balance the unclosed tags appropriate, but it doesn't close the quotation mark.

For example, if my content body is the following one:

<ul>
  <li><a href="http://google.com">google.com</a></li>
</ul>

The teaser breaks in the middle of the URL:

<ul>
  <li><a href="http://goog

Then the tags are closed but no closing quote or the end of the opening tag:

<ul>
  <li><a href="http://goog </a></li>
</ul>

The result is a broken theme. Am I doing anything wrong? Is there anything that is mis-configured?

2 Answers 2

3

Doesn't look like it's a problem on your side. You can try the following:

drush php-eval '$text = "<ul><a href=\"http://goo"; print $text . "\n"; print _filter_htmlcorrector($text) . "\n";'

And for me the results are:

<ul><a href="http://goo
<ul><a href="http://goo</ul>

(The second line is the output of _filter_htmlcorrector().)

It would be worth seeing if there's an issue for this already, and if not creating one. I find the built-in HTML corrector too limiting anyway (it always strips styles for example IIRC), and use htmLawed. With that you get:

drush php-eval '$text = "<ul><a href=\"http://goo"; print $text . "\n"; print htmLawed_filter('process', 0, -1, $text) . "\n";'

Results:

<ul><a href="http://goo
<ul> </ul>

(Again, second line is the cleaned output - it's simply stripped the incomplete tag.)

1
  • Thanks! I was looking at htmlawed and htmlpurifier as possible solutions, but was looking for confirmation that this was a bug first. Thanks for that confirmation!
    – adharris
    Commented Oct 4, 2011 at 17:47
0

Got it! The lightweight solution is to remove malformed html tag from the very end of the string:

function YOUR_MODULE_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) {
  switch ($op) {
    case 'presave':
      // Cleanup teaser from the mallformed tag at the end of the string.
      $node->teaser = preg_replace('~<\w?[^>]*$~', '', $node->teaser);
      break;
  }
}

NOTE! Existing nodes should be updated to cleanup their teasers.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.