Issue Bug Closed

#39261parseFunc does not handle nested tags correct

Martin Holtz 07/25/12, 16:40 updated 04/01/20, 21:14

Description

The _parseFunc function is not able to detect nested tags properly. The function is searching for the first closing tag, regardless other opening tags of the same type.

Test Code:

page.10 = TEXT
page.10.value (
  <ul>
    <li>first</li>
    <li>second
        <ul>
        <li>first sub</li>
        <li>second sub</li>
        </ul>
    </li>
  </ul>
)
page.10.parseFunc {
  tags.li = TEXT
  tags.li.wrap = <li>LI:|</li>
  tags.li.current = 1
}

Expected:

<ul>
    <li>LI:first</li>
    <li>LI:second
        <ul>
        <li>LI:first sub</li>
        <li>LI:second sub</li>
        </ul>
    </li>
  </ul>

Actual result:

<ul>
    <li>LI:first</li>
    <li>LI:second
        <ul>
        <li>first sub</li>
        <li>LI:second sub</li>
        </ul>
    </li>
  </ul>

The relevant code in class.tslib_content.php -> _parseFunc($theValue, $conf):

// If we're inside a currentTag, just take it to the end of that tag!
$tempContent = strtolower(substr($theValue, $pointer));
$len = strpos($tempContent, '</' . $currentTag[0]);
While parsing the content of “
  • second …”, the first closing tag which is found is the closing tag of “
  • first sub
  • “. So, internal “
  • second
    • first sub
    • is handled as one tag. On the end everything is concatinated in the correct order, so as long as you do not want to alter such an tag, you will not notice.

      With this TypoScript, you get broken markup:

      page.10.parseFunc {
        tags.li = TEXT
        tags.li.value =  <li>Static</li>
      }

      Result is:

        <ul>
          <li>Static</li>
          <li>Static</li>
              <li>Static</li>
              </ul>
          </li>
        </ul>
  • Reviews 2