Skip to content

Commit fc09cff

Browse files
authored
[BUGFIX] Prevent shifting of line numbers (#1358) (#1368)
When removing the `<html xmlns` declarations from the template, line breaks within the `<html>` tags were also removed. This lead to invalid line numbers reported by the template parser. With this change, the affected `<html>` tag is replaced with the matching number of newlines.
1 parent c409976 commit fc09cff

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

src/Core/Parser/TemplateProcessor/NamespaceDetectionTemplateProcessor.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,8 @@ public function registerNamespacesFromTemplateSource(string $templateSource): st
114114
$viewHelperResolver->addLocalNamespace($set[1], $namespacePhp);
115115
}
116116
if (strpos($matches[0], 'data-namespace-typo3-fluid="true"')) {
117-
$templateSource = str_replace($matches[0], '', $templateSource);
117+
$removedNewlines = substr_count($matches[0], "\n");
118+
$templateSource = str_replace($matches[0], str_repeat("\n", $removedNewlines), $templateSource);
118119
$closingTagName = $matches[1];
119120
$closingTag = '</' . $closingTagName . '>';
120121
if (strpos($templateSource, $closingTag)) {

tests/Functional/Core/Parser/TemplateProcessor/NamespaceDetectionTemplateProcessorTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,13 +96,13 @@ public static function preProcessSourceExtractsNamespacesDataProvider(): array
9696
],
9797
'supports xmlns detection, multiple' => [
9898
['f' => ['TYPO3Fluid\Fluid\ViewHelpers']],
99-
'<html xmlns:x="http://typo3.org/ns/X/Y/ViewHelpers" xmlns:z="http://typo3.org/ns/X/Z/ViewHelpers" data-namespace-typo3-fluid="true">' . PHP_EOL . '</html>',
99+
'<html' . PHP_EOL . 'xmlns:x="http://typo3.org/ns/X/Y/ViewHelpers"' . PHP_EOL . 'xmlns:z="http://typo3.org/ns/X/Z/ViewHelpers"' . PHP_EOL . 'data-namespace-typo3-fluid="true"' . PHP_EOL . '>' . PHP_EOL . '</html>' . PHP_EOL,
100100
[
101101
'f' => ['TYPO3Fluid\Fluid\ViewHelpers'],
102102
'x' => ['X\\Y\\ViewHelpers'],
103103
'z' => ['X\\Z\\ViewHelpers'],
104104
],
105-
PHP_EOL,
105+
PHP_EOL . PHP_EOL . PHP_EOL . PHP_EOL . PHP_EOL . PHP_EOL,
106106
],
107107
'supports expression style namespace detection, camelCase' => [
108108
['f' => ['TYPO3Fluid\Fluid\ViewHelpers']],

0 commit comments

Comments
 (0)