Bug #39261

parseFunc does not handle nested tags correct

Added by Martin Holtz 11 months ago. Updated 3 months ago.

Status:New Start date:2012-07-25
Priority:Could have Due date:
Assignee:- % Done:

0%

Category:TypoScript
Target version:-
TYPO3 Version:4.7 Complexity:hard
PHP Version:
Votes: 1 (View)

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 "<li>second ...", the first closing tag which is found is the closing tag of "<li>first sub</li>". So, internal "<li>second<ul><li>first sub</li> 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>

Also available in: Atom PDF